]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
GL_ARB_multisampling defs (vid_multisampling) and alpha-to-coverage effect (r_transpa...
authorvortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 8 May 2011 21:55:18 +0000 (21:55 +0000)
committervortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 8 May 2011 21:55:18 +0000 (21:55 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11136 d7cf8633-e32d-0410-b094-e92efae38249

gl_backend.c
gl_rmain.c
glquake.h
vid.h
vid_sdl.c
vid_shared.c

index dc46cc719dcd21016f55b6e36522f0dced00ab9d..6fc886ba0052b212304e5857536ddbcc4928ec79 100644 (file)
@@ -1381,6 +1381,7 @@ static int d3dstencilopforglfunc(int f)
 }
 #endif
 
+extern cvar_t r_transparent_alphatocoverage;
 
 static void GL_Backend_ResetState(void)
 {
@@ -1436,7 +1437,7 @@ static void GL_Backend_ResetState(void)
 
                qglColorMask(1, 1, 1, 1);CHECKGLERROR
                qglAlphaFunc(gl_state.alphafunc, gl_state.alphafuncvalue);CHECKGLERROR
-               qglDisable(GL_ALPHA_TEST);CHECKGLERROR
+               qglDisable((vid_multisampling.integer && r_transparent_alphatocoverage.integer) ? GL_SAMPLE_ALPHA_TO_COVERAGE_ARB : GL_ALPHA_TEST);CHECKGLERROR
                qglBlendFunc(gl_state.blendfunc1, gl_state.blendfunc2);CHECKGLERROR
                qglDisable(GL_BLEND);CHECKGLERROR
                qglCullFace(gl_state.cullface);CHECKGLERROR
@@ -2133,11 +2134,11 @@ void GL_AlphaTest(int state)
                        CHECKGLERROR
                        if (gl_state.alphatest)
                        {
-                               qglEnable(GL_ALPHA_TEST);CHECKGLERROR
+                               qglEnable((vid_multisampling.integer && r_transparent_alphatocoverage.integer) ? GL_SAMPLE_ALPHA_TO_COVERAGE_ARB : GL_ALPHA_TEST);CHECKGLERROR
                        }
                        else
                        {
-                               qglDisable(GL_ALPHA_TEST);CHECKGLERROR
+                               qglDisable((vid_multisampling.integer && r_transparent_alphatocoverage.integer) ? GL_SAMPLE_ALPHA_TO_COVERAGE_ARB : GL_ALPHA_TEST);CHECKGLERROR
                        }
                        break;
                case RENDERPATH_D3D9:
index 81ada1722f59e1dca03c077e662fc2b559b8b5e4..996fd2d9eb976ab828bca401870667ec0bd9aae8 100644 (file)
@@ -72,6 +72,7 @@ cvar_t r_farclip_world = {0, "r_farclip_world", "2", "adds map size to farclip m
 cvar_t r_nearclip = {0, "r_nearclip", "1", "distance from camera of nearclip plane" };
 cvar_t r_deformvertexes = {0, "r_deformvertexes", "1", "allows use of deformvertexes in shader files (can be turned off to check performance impact)"};
 cvar_t r_transparent = {0, "r_transparent", "1", "allows use of transparent surfaces (can be turned off to check performance impact)"};
+cvar_t r_transparent_alphatocoverage = {0, "r_transparent_alphatocoverage", "0", "enables alpha-to-coverage antialiasing technique on alphatest surfaces, this is not yet finished as multisampling is not used"};
 cvar_t r_showoverdraw = {0, "r_showoverdraw", "0", "shows overlapping geometry"};
 cvar_t r_showbboxes = {0, "r_showbboxes", "0", "shows bounding boxes of server entities, value controls opacity scaling (1 = 10%,  10 = 100%)"};
 cvar_t r_showsurfaces = {0, "r_showsurfaces", "0", "1 shows surfaces as different colors, or a value of 2 shows triangle draw order (for analyzing whether meshes are optimized for vertex cache)"};
@@ -2092,6 +2093,19 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting,
        r_waterstate_waterplane_t *waterplane = (r_waterstate_waterplane_t *)surfacewaterplane;
        if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
                permutation |= SHADERPERMUTATION_ALPHAKILL;
+       // Alpha to Coverage
+       // fixme: move to gl_backend
+       if (vid_multisampling.integer && r_transparent_alphatocoverage.integer)
+       {
+               if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
+               {
+                       qglEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);CHECKGLERROR
+               }
+               else
+               {
+                       qglDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);CHECKGLERROR
+               }
+       }
        if (rsurface.texture->r_water_waterscroll[0] && rsurface.texture->r_water_waterscroll[1])
                permutation |= SHADERPERMUTATION_NORMALMAPSCROLLBLEND; // todo: make generic
        if (rsurfacepass == RSURFPASS_BACKGROUND)
@@ -4049,6 +4063,7 @@ void GL_Main_Init(void)
        Cvar_RegisterVariable(&r_nearclip);
        Cvar_RegisterVariable(&r_deformvertexes);
        Cvar_RegisterVariable(&r_transparent);
+       Cvar_RegisterVariable(&r_transparent_alphatocoverage);
        Cvar_RegisterVariable(&r_showoverdraw);
        Cvar_RegisterVariable(&r_showbboxes);
        Cvar_RegisterVariable(&r_showsurfaces);
index 120c453ed238af0abe07e5acd8997dbe41da516b..8313cf67c40cf215d679a329ab6ca7436775e581 100644 (file)
--- a/glquake.h
+++ b/glquake.h
@@ -989,6 +989,20 @@ extern void (GLAPIENTRY *qglGetQueryObjectuivARB)(GLuint qid, GLenum pname, GLui
 
 //GL_ARB_texture_gather
 
+//GL_ARB_multisample
+#define GL_MULTISAMPLE_ARB              0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_ARB      0x809F
+#define GL_SAMPLE_COVERAGE_ARB          0x80A0
+#define GL_SAMPLE_BUFFERS_ARB           0x80A8
+#define GL_SAMPLES_ARB                  0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE_ARB    0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT_ARB   0x80AB
+#define GL_MULTISAMPLE_BIT_ARB          0x20000000
+extern void (GLAPIENTRY *qglSampleCoverageARB)(GLclampf value, GLboolean invert);
+
+extern void (GLAPIENTRY *qglPointSize)(GLfloat size);
+
 #define DEBUGGL
 
 #ifdef DEBUGGL
diff --git a/vid.h b/vid.h
index 6c42deba1fae61048571c0b4555a43b275acf7bb..cea3a1ec76ce0e496f6920dd48e3e0fed83d01f5 100644 (file)
--- a/vid.h
+++ b/vid.h
@@ -69,6 +69,7 @@ typedef struct viddef_support_s
        qboolean ext_texture_edge_clamp;
        qboolean ext_texture_filter_anisotropic;
        qboolean ext_texture_srgb;
+       qboolean arb_multisample;
 }
 viddef_support_t;
 
@@ -152,6 +153,7 @@ extern cvar_t vid_width;
 extern cvar_t vid_height;
 extern cvar_t vid_bitsperpixel;
 extern cvar_t vid_samples;
+extern cvar_t vid_multisampling;
 extern cvar_t vid_refreshrate;
 extern cvar_t vid_userefreshrate;
 extern cvar_t vid_vsync;
index c301160af09adffd8a3fbd0c507ebd00f7389a33..f7f95bb4ecce1a247b375b73fe67cbca8da978c5 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -2203,6 +2203,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
                SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1);
                SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, mode->samples);
        }
+
 #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
        if (vid_vsync.integer)
                SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
@@ -2292,6 +2293,21 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        vid_usingmouse = false;
        vid_usinghidecursor = false;
 
+       // enable multisampling
+       if (mode->samples > 1 && vid_multisampling.integer)
+       {
+               if (vid.support.arb_multisample)
+                       qglEnable(GL_MULTISAMPLE_ARB);
+               else
+               {
+                       Cvar_SetValueQuick(&vid_multisampling, 0);
+                       qglDisable(GL_MULTISAMPLE_ARB);
+               }
+       }
+       else
+               qglDisable(GL_MULTISAMPLE_ARB);
+       CHECKGLERROR
+               
 #if SETVIDEOMODE
        SDL_WM_GrabInput(SDL_GRAB_OFF);
 #endif
index fad67d7f5379f3e02ac0878cbaa70d0643a1f54c..aad8446ee4d76714ff714ff6bc0db196dbb66cdf 100644 (file)
@@ -59,6 +59,7 @@ cvar_t vid_width = {CVAR_SAVE, "vid_width", "640", "resolution"};
 cvar_t vid_height = {CVAR_SAVE, "vid_height", "480", "resolution"};
 cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "32", "how many bits per pixel to render at (32 or 16, 32 is recommended)"};
 cvar_t vid_samples = {CVAR_SAVE, "vid_samples", "1", "how many anti-aliasing samples per pixel to request from the graphics driver (4 is recommended, 1 is faster)"};
+cvar_t vid_multisampling = {CVAR_SAVE, "vid_multisampling", "0", "Make use of GL_AGB_MULTISAMPLING for advaced anti-aliasing techniques such as Alpha-To-Coverage, not yet finished"};
 cvar_t vid_refreshrate = {CVAR_SAVE, "vid_refreshrate", "60", "refresh rate to use, in hz (higher values flicker less, if supported by your monitor)"};
 cvar_t vid_userefreshrate = {CVAR_SAVE, "vid_userefreshrate", "0", "set this to 1 to make vid_refreshrate used, or to 0 to let the engine choose a sane default"};
 cvar_t vid_stereobuffer = {CVAR_SAVE, "vid_stereobuffer", "0", "enables 'quad-buffered' stereo rendering for stereo shutterglasses, HMD (head mounted display) devices, or polarized stereo LCDs, if supported by your drivers"};
@@ -397,6 +398,8 @@ void (GLAPIENTRY *qglGetQueryivARB)(GLenum target, GLenum pname, GLint *params);
 void (GLAPIENTRY *qglGetQueryObjectivARB)(GLuint qid, GLenum pname, GLint *params);
 void (GLAPIENTRY *qglGetQueryObjectuivARB)(GLuint qid, GLenum pname, GLuint *params);
 
+void (GLAPIENTRY *qglSampleCoverageARB)(GLclampf value, GLboolean invert);
+
 #if _MSC_VER >= 1400
 #define sscanf sscanf_s
 #endif
@@ -805,6 +808,12 @@ static dllfunction_t drawbuffersfuncs[] =
        {NULL, NULL}
 };
 
+static dllfunction_t multisamplefuncs[] =
+{
+       {"glSampleCoverageARB",          (void **) &qglSampleCoverageARB},
+       {NULL, NULL}
+};
+
 void VID_ClearExtensions(void)
 {
        // VorteX: reset extensions info cvar, it got filled by GL_CheckExtension
@@ -892,6 +901,8 @@ void VID_CheckExtensions(void)
        vid.support.ext_texture_edge_clamp = GL_CheckExtension("GL_EXT_texture_edge_clamp", NULL, "-noedgeclamp", false) || GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "-noedgeclamp", false);
        vid.support.ext_texture_filter_anisotropic = GL_CheckExtension("GL_EXT_texture_filter_anisotropic", NULL, "-noanisotropy", false);
        vid.support.ext_texture_srgb = GL_CheckExtension("GL_EXT_texture_sRGB", NULL, "-nosrgb", false);
+       vid.support.arb_multisample = GL_CheckExtension("GL_ARB_multisample", multisamplefuncs, "-nomultisample", false);
+
 // COMMANDLINEOPTION: GL: -noshaders disables use of OpenGL 2.0 shaders (which allow pixel shader effects, can improve per pixel lighting performance and capabilities)
 // COMMANDLINEOPTION: GL: -noanisotropy disables GL_EXT_texture_filter_anisotropic (allows higher quality texturing)
 // COMMANDLINEOPTION: GL: -noblendminmax disables GL_EXT_blend_minmax
@@ -916,6 +927,7 @@ void VID_CheckExtensions(void)
 // COMMANDLINEOPTION: GL: -notexturenonpoweroftwo disables GL_ARB_texture_non_power_of_two (which saves video memory if it is supported, but crashes on some buggy drivers)
 // COMMANDLINEOPTION: GL: -novbo disables GL_ARB_vertex_buffer_object (which accelerates rendering)
 // COMMANDLINEOPTION: GL: -nosrgb disables GL_EXT_texture_sRGB (which is used for higher quality non-linear texture gamma)
+// COMMANDLINEOPTION: GL: -nomultisample disables GL_ARB_multisample
 
        if (vid.support.arb_draw_buffers)
                qglGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, (GLint*)&vid.maxdrawbuffers);
@@ -1269,6 +1281,7 @@ void VID_Shared_Init(void)
        Cvar_RegisterVariable(&vid_height);
        Cvar_RegisterVariable(&vid_bitsperpixel);
        Cvar_RegisterVariable(&vid_samples);
+       Cvar_RegisterVariable(&vid_multisampling);
        Cvar_RegisterVariable(&vid_refreshrate);
        Cvar_RegisterVariable(&vid_userefreshrate);
        Cvar_RegisterVariable(&vid_stereobuffer);