From fbce506ea7bd59082fe9c903989e7315dc7b3885 Mon Sep 17 00:00:00 2001 From: vortex Date: Fri, 13 May 2011 21:37:16 +0000 Subject: [PATCH] Multisampling initialisation moved from vid_sdl to gl_backend. Make cubemaps array dynamic (segments are allocated on load), this uses less memory, and MAX_CUBEMAPS was raised. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11147 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=e272f5efe910b09242dd42c4044aa85bfe9b1710 --- gl_backend.c | 29 +++++++++++++++++++++++++++++ gl_backend.h | 1 + gl_rmain.c | 47 ++++++++++++++++++++++++++++++++++++++--------- quakedef.h | 4 ++-- vid_sdl.c | 21 --------------------- vid_shared.c | 13 +++++++++++++ 6 files changed, 83 insertions(+), 32 deletions(-) diff --git a/gl_backend.c b/gl_backend.c index 5fbf7979..0efde344 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -2120,6 +2120,35 @@ void GL_CullFace(int state) } } +void GL_MultiSampling(qboolean state) +{ + switch(vid.renderpath) + { + case RENDERPATH_GL11: + case RENDERPATH_GL13: + case RENDERPATH_GLES1: + case RENDERPATH_GL20: + case RENDERPATH_GLES2: + if (vid.support.arb_multisample) + { + if (state) + qglEnable(GL_MULTISAMPLE_ARB); + else + qglDisable(GL_MULTISAMPLE_ARB); + CHECKGLERROR + } + break; + case RENDERPATH_D3D9: + break; + case RENDERPATH_D3D10: + break; + case RENDERPATH_D3D11: + break; + case RENDERPATH_SOFT: + break; + } +} + void GL_AlphaTest(int state) { if (gl_state.alphatest != state) diff --git a/gl_backend.h b/gl_backend.h index 82b9ed4f..8f6e5ab1 100644 --- a/gl_backend.h +++ b/gl_backend.h @@ -40,6 +40,7 @@ void R_SetStencil(qboolean enable, int writemask, int fail, int zfail, int zpass void GL_PolygonOffset(float planeoffset, float depthoffset); void GL_CullFace(int state); void GL_AlphaTest(int state); +void GL_MultiSampling(qboolean state); void GL_ColorMask(int r, int g, int b, int a); void GL_Color(float cr, float cg, float cb, float ca); void GL_ActiveTexture(unsigned int num); diff --git a/gl_rmain.c b/gl_rmain.c index 8deabbc7..ef4ee010 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -282,7 +282,7 @@ typedef struct cubemapinfo_s cubemapinfo_t; int r_texture_numcubemaps; -cubemapinfo_t r_texture_cubemaps[MAX_CUBEMAPS]; +cubemapinfo_t *r_texture_cubemaps[MAX_CUBEMAPS]; unsigned int r_queries[MAX_OCCLUSION_QUERIES]; unsigned int r_numqueries; @@ -3741,14 +3741,36 @@ rtexture_t *R_GetCubemap(const char *basename) { int i; for (i = 0;i < r_texture_numcubemaps;i++) - if (!strcasecmp(r_texture_cubemaps[i].basename, basename)) - return r_texture_cubemaps[i].texture ? r_texture_cubemaps[i].texture : r_texture_whitecube; + if (r_texture_cubemaps[i] != NULL) + if (!strcasecmp(r_texture_cubemaps[i]->basename, basename)) + return r_texture_cubemaps[i]->texture ? r_texture_cubemaps[i]->texture : r_texture_whitecube; if (i >= MAX_CUBEMAPS) return r_texture_whitecube; r_texture_numcubemaps++; - strlcpy(r_texture_cubemaps[i].basename, basename, sizeof(r_texture_cubemaps[i].basename)); - r_texture_cubemaps[i].texture = R_LoadCubemap(r_texture_cubemaps[i].basename); - return r_texture_cubemaps[i].texture; + r_texture_cubemaps[i] = (cubemapinfo_t *)Mem_Alloc(r_main_mempool, sizeof(cubemapinfo_t)); + strlcpy(r_texture_cubemaps[i]->basename, basename, sizeof(r_texture_cubemaps[i]->basename)); + r_texture_cubemaps[i]->texture = R_LoadCubemap(r_texture_cubemaps[i]->basename); + return r_texture_cubemaps[i]->texture; +} + +void R_FreeCubemap(const char *basename) +{ + int i; + + for (i = 0;i < r_texture_numcubemaps;i++) + { + if (r_texture_cubemaps[i] != NULL) + { + if (r_texture_cubemaps[i]->texture) + { + if (developer_loading.integer) + Con_DPrintf("unloading cubemap \"%s\"\n", r_texture_cubemaps[i]->basename); + R_FreeTexture(r_texture_cubemaps[i]->texture); + Mem_Free(r_texture_cubemaps[i]); + r_texture_cubemaps[i] = NULL; + } + } + } } void R_FreeCubemaps(void) @@ -3757,9 +3779,13 @@ void R_FreeCubemaps(void) for (i = 0;i < r_texture_numcubemaps;i++) { if (developer_loading.integer) - Con_DPrintf("unloading cubemap \"%s\"\n", r_texture_cubemaps[i].basename); - if (r_texture_cubemaps[i].texture) - R_FreeTexture(r_texture_cubemaps[i].texture); + Con_DPrintf("unloading cubemap \"%s\"\n", r_texture_cubemaps[i]->basename); + if (r_texture_cubemaps[i] != NULL) + { + if (r_texture_cubemaps[i]->texture) + R_FreeTexture(r_texture_cubemaps[i]->texture); + Mem_Free(r_texture_cubemaps[i]); + } } r_texture_numcubemaps = 0; } @@ -3911,6 +3937,9 @@ void gl_main_start(void) hlslshaderstring = NULL; memset(&r_svbsp, 0, sizeof (r_svbsp)); + memset(r_texture_cubemaps, 0, sizeof(r_texture_cubemaps)); + r_texture_numcubemaps = 0; + r_refdef.fogmasktable_density = 0; } diff --git a/quakedef.h b/quakedef.h index 4cc7527c..a712fe73 100644 --- a/quakedef.h +++ b/quakedef.h @@ -86,7 +86,7 @@ extern char engineversion[128]; #define MAX_NETWM_ICON 1026 // one 32x32 #define MAX_WATERPLANES 2 -#define MAX_CUBEMAPS 64 +#define MAX_CUBEMAPS 1024 #define MAX_EXPLOSIONS 8 #define MAX_DLIGHTS 16 #define MAX_CACHED_PICS 1024 // this is 144 bytes each (or 152 on 64bit) @@ -153,7 +153,7 @@ extern char engineversion[128]; #define MAX_NETWM_ICON 352822 // 16x16, 22x22, 24x24, 32x32, 48x48, 64x64, 128x128, 256x256, 512x512 #define MAX_WATERPLANES 16 ///< max number of water planes visible (each one causes additional view renders) -#define MAX_CUBEMAPS 256 ///< max number of cubemap textures loaded for light filters +#define MAX_CUBEMAPS 1024 ///< max number of cubemap textures loaded for light filters #define MAX_EXPLOSIONS 64 ///< max number of explosion shell effects active at once (not particle related) #define MAX_DLIGHTS 256 ///< max number of dynamic lights (rocket flashes, etc) in scene at once #define MAX_CACHED_PICS 1024 ///< max number of 2D pics loaded at once diff --git a/vid_sdl.c b/vid_sdl.c index fdd70caa..19373994 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -2292,27 +2292,6 @@ qboolean VID_InitModeGL(viddef_mode_t *mode) vid_hasfocus = true; vid_usingmouse = false; vid_usinghidecursor = false; - - // enable multisampling - if (vid_multisampling.integer) - { - if (vid.support.arb_multisample) - { - qglEnable(GL_MULTISAMPLE_ARB); - // it seems that enabling GL_MULTISAMPLE_ARB forces antialiasing to always work, fix the cvar as well - // make sure vid_sample is at least 2 to make things correct - if (vid_samples.integer < 2) - Cvar_SetValueQuick(&vid_samples, 0); - } - else - { - Cvar_SetValueQuick(&vid_multisampling, 0); - qglDisable(GL_MULTISAMPLE_ARB); - } - } - else - qglDisable(GL_MULTISAMPLE_ARB); - CHECKGLERROR #if SETVIDEOMODE SDL_WM_GrabInput(SDL_GRAB_OFF); diff --git a/vid_shared.c b/vid_shared.c index aad8446e..6f79d4d1 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -1304,6 +1304,15 @@ void VID_Shared_Init(void) int VID_Mode(int fullscreen, int width, int height, int bpp, float refreshrate, int stereobuffer, int samples) { viddef_mode_t mode; + + // multisampling should set at least 2 samples + if (vid.support.arb_multisample) + { + GL_MultiSampling(false); + if (vid_multisampling.integer) + samples = max(2, samples); + } + memset(&mode, 0, sizeof(mode)); mode.fullscreen = fullscreen != 0; mode.width = width; @@ -1342,6 +1351,10 @@ int VID_Mode(int fullscreen, int width, int height, int bpp, float refreshrate, Cvar_SetValueQuick(&vid_refreshrate, vid.mode.refreshrate); Cvar_SetValueQuick(&vid_stereobuffer, vid.mode.stereobuffer); + // activate multisampling + if (vid_multisampling.integer) + GL_MultiSampling(true); + return true; } else -- 2.39.2