]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_shared.c
reduced memory usage by around 20MB (no longer allocates interleaved
[xonotic/darkplaces.git] / vid_shared.c
index 20f2b3e1dd3dd8f74e0b5d2226c8924b1cc98bc5..eae470f0204ac6fdee2220ad1d28c4060c7b2fa9 100644 (file)
@@ -6,6 +6,15 @@
 #include <Cg/cgGL.h>
 #endif
 
+#ifdef SUPPORTD3D
+#include <d3d9.h>
+#ifdef _MSC_VER
+#pragma comment(lib, "d3d9.lib")
+#endif
+
+LPDIRECT3DDEVICE9 vid_d3d9dev;
+#endif
+
 // global video state
 viddef_t vid;
 
@@ -790,13 +799,38 @@ static dllfunction_t drawbuffersfuncs[] =
        {NULL, NULL}
 };
 
-void VID_CheckExtensions(void)
+void VID_ClearExtensions(void)
 {
+       // VorteX: reset extensions info cvar, it got filled by GL_CheckExtension
+       Cvar_SetQuick(&gl_info_extensions, "");
+
        // clear the extension flags
        memset(&vid.support, 0, sizeof(vid.support));
+       vid.renderpath = RENDERPATH_GL11;
+       vid.useinterleavedarrays = false;
+       vid.forcevbo = false;
+       vid.maxtexturesize_2d = 0;
+       vid.maxtexturesize_3d = 0;
+       vid.maxtexturesize_cubemap = 0;
+       vid.texunits = 1;
+       vid.teximageunits = 1;
+       vid.texarrayunits = 1;
+       vid.max_anisotropy = 1;
+       vid.maxdrawbuffers = 1;
 
-       // VorteX: reset extensions info cvar, it got filled by GL_CheckExtension
-       Cvar_SetQuick(&gl_info_extensions, "");
+       // this is a complete list of all functions that are directly checked in the renderer
+       qglDrawRangeElements = NULL;
+       qglDrawBuffer = NULL;
+       qglPolygonStipple = NULL;
+       qglFlush = NULL;
+       qglActiveTexture = NULL;
+       qglGetCompressedTexImageARB = NULL;
+       qglFramebufferTexture2DEXT = NULL;
+       qglDrawBuffersARB = NULL;
+}
+
+void VID_CheckExtensions(void)
+{
        if (!GL_CheckExtension("1.1", opengl110funcs, NULL, false))
                Sys_Error("OpenGL 1.1.0 functions not found");
 
@@ -804,7 +838,6 @@ void VID_CheckExtensions(void)
 
        Con_DPrint("Checking OpenGL extensions...\n");
 
-       vid.forcevbo = false;
        vid.support.amd_texture_texture4 = GL_CheckExtension("GL_AMD_texture_texture4", NULL, "-notexture4", false);
        vid.support.arb_depth_texture = GL_CheckExtension("GL_ARB_depth_texture", NULL, "-nodepthtexture", false);
        vid.support.arb_draw_buffers = GL_CheckExtension("GL_ARB_draw_buffers", drawbuffersfuncs, "-nodrawbuffers", false);
@@ -819,7 +852,6 @@ void VID_CheckExtensions(void)
        vid.support.arb_texture_env_combine = GL_CheckExtension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || GL_CheckExtension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
        vid.support.arb_texture_gather = GL_CheckExtension("GL_ARB_texture_gather", NULL, "-notexturegather", false);
        vid.support.arb_texture_non_power_of_two = GL_CheckExtension("GL_ARB_texture_non_power_of_two", NULL, "-notexturenonpoweroftwo", false);
-       vid.support.arb_texture_rectangle = GL_CheckExtension("GL_ARB_texture_rectangle", NULL, "-norectangle", false);
        vid.support.arb_vertex_buffer_object = GL_CheckExtension("GL_ARB_vertex_buffer_object", vbofuncs, "-novbo", false);
        vid.support.arb_vertex_shader = GL_CheckExtension("GL_ARB_vertex_shader", vertexshaderfuncs, "-novertexshader", false);
        vid.support.ati_separate_stencil = GL_CheckExtension("2.0", gl2separatestencilfuncs, "-noseparatestencil", true) || GL_CheckExtension("GL_ATI_separate_stencil", atiseparatestencilfuncs, "-noseparatestencil", false);
@@ -845,7 +877,6 @@ void VID_CheckExtensions(void)
 // COMMANDLINEOPTION: GL: -nofragmentshader disables GL_ARB_fragment_shader (allows pixel shader effects, can improve per pixel lighting performance and capabilities)
 // COMMANDLINEOPTION: GL: -nomtex disables GL_ARB_multitexture (required for faster map rendering)
 // COMMANDLINEOPTION: GL: -noocclusionquery disables GL_ARB_occlusion_query (which allows coronas to fade according to visibility, and potentially used for rendering optimizations)
-// COMMANDLINEOPTION: GL: -norectangle disables GL_ARB_texture_rectangle (required for bumpmapping)
 // COMMANDLINEOPTION: GL: -nos3tc disables GL_EXT_texture_compression_s3tc (which allows use of .dds texture caching)
 // COMMANDLINEOPTION: GL: -noseparatestencil disables use of OpenGL2.0 glStencilOpSeparate and GL_ATI_separate_stencil extensions (which accelerate shadow rendering)
 // COMMANDLINEOPTION: GL: -noshaderobjects disables GL_ARB_shader_objects (required for vertex shader and fragment shader)
@@ -860,15 +891,6 @@ void VID_CheckExtensions(void)
 // COMMANDLINEOPTION: GL: -novbo disables GL_ARB_vertex_buffer_object (which accelerates rendering)
 // COMMANDLINEOPTION: GL: -novertexshader disables GL_ARB_vertex_shader (allows vertex shader effects)
 
-       vid.maxtexturesize_2d = 0;
-       vid.maxtexturesize_3d = 0;
-       vid.maxtexturesize_cubemap = 0;
-       vid.texunits = 1;
-       vid.teximageunits = 1;
-       vid.texarrayunits = 1;
-       vid.max_anisotropy = 1;
-       vid.maxdrawbuffers = 1;
-
        if (vid.support.arb_draw_buffers)
                qglGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, (GLint*)&vid.maxdrawbuffers);
 
@@ -892,8 +914,6 @@ void VID_CheckExtensions(void)
                qglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*)&vid.max_anisotropy);
        if (vid.support.arb_texture_cube_map)
                qglGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, (GLint*)&vid.maxtexturesize_cubemap);
-       if (vid.support.arb_texture_rectangle)
-               qglGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, (GLint*)&vid.maxtexturesize_rectangle);
        if (vid.support.ext_texture_3d)
                qglGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_3d);
 
@@ -917,6 +937,7 @@ void VID_CheckExtensions(void)
                vid.texarrayunits = bound(8, vid.texarrayunits, MAX_TEXTUREUNITS);
                Con_DPrintf("Using GL2.0 rendering path - %i texture matrix, %i texture images, %i texcoords%s\n", vid.texunits, vid.teximageunits, vid.texarrayunits, vid.support.ext_framebuffer_object ? ", shadowmapping supported" : "");
                vid.renderpath = RENDERPATH_GL20;
+               vid.useinterleavedarrays = false;
        }
 #ifdef SUPPORTCG
        else if (vid_cggl.integer && (vid.cgcontext = cgCreateContext()))
@@ -926,6 +947,7 @@ void VID_CheckExtensions(void)
                vid.texarrayunits = 8;
                Con_DPrintf("Using NVIDIA Cg rendering path - %i texture matrix, %i texture images, %i texcoords%s\n", vid.texunits, vid.teximageunits, vid.texarrayunits, vid.support.ext_framebuffer_object ? ", shadowmapping supported" : "");
                vid.renderpath = RENDERPATH_CGGL;
+               vid.useinterleavedarrays = false;
        }
 #endif
        else if (vid.support.arb_texture_env_combine && vid.texunits >= 2 && vid_gl13.integer)
@@ -936,6 +958,7 @@ void VID_CheckExtensions(void)
                vid.texarrayunits = vid.texunits;
                Con_DPrintf("Using GL1.3 rendering path - %i texture units, single pass rendering\n", vid.texunits);
                vid.renderpath = RENDERPATH_GL13;
+               vid.useinterleavedarrays = false;
        }
        else
        {
@@ -944,6 +967,7 @@ void VID_CheckExtensions(void)
                vid.texarrayunits = vid.texunits;
                Con_DPrintf("Using GL1.1 rendering path - %i texture units, two pass rendering\n", vid.texunits);
                vid.renderpath = RENDERPATH_GL11;
+               vid.useinterleavedarrays = false;
        }
 
        // VorteX: set other info (maybe place them in VID_InitMode?)
@@ -1036,6 +1060,9 @@ void VID_UpdateGamma(qboolean force, int rampsize)
        {
        case RENDERPATH_GL20:
        case RENDERPATH_CGGL:
+       case RENDERPATH_D3D9:
+       case RENDERPATH_D3D10:
+       case RENDERPATH_D3D11:
                if (v_glslgamma.integer)
                        wantgamma = 0;
                break;
@@ -1236,6 +1263,7 @@ int VID_Mode(int fullscreen, int width, int height, int bpp, float refreshrate,
        mode.stereobuffer = stereobuffer != 0;
        mode.samples = samples;
        cl_ignoremousemoves = 2;
+       VID_ClearExtensions();
        if (VID_InitMode(&mode))
        {
                // accept the (possibly modified) mode