]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
Fix engine not starting on Windows if linked against SDL > 2.0.5
[xonotic/darkplaces.git] / model_brush.c
index eb37da166000f2d334051eb23946428bdad4c02f..9eb87f13caca65e8535a6704c7a8621c543b9bba 100644 (file)
@@ -1636,8 +1636,8 @@ static void R_Q1BSP_LoadSplitSky (unsigned char *src, int width, int height, int
                }
        }
 
-       loadmodel->brush.solidskyskinframe = R_SkinFrame_LoadInternalBGRA("sky_solidtexture", 0         , (unsigned char *) solidpixels, w, h, vid.sRGB3D);
-       loadmodel->brush.alphaskyskinframe = R_SkinFrame_LoadInternalBGRA("sky_alphatexture", TEXF_ALPHA, (unsigned char *) alphapixels, w, h, vid.sRGB3D);
+       loadmodel->brush.solidskyskinframe = R_SkinFrame_LoadInternalBGRA("sky_solidtexture", 0         , (unsigned char *) solidpixels, w, h, 0, 0, 0, vid.sRGB3D);
+       loadmodel->brush.alphaskyskinframe = R_SkinFrame_LoadInternalBGRA("sky_alphatexture", TEXF_ALPHA, (unsigned char *) alphapixels, w, h, 0, 0, 0, vid.sRGB3D);
        Mem_Free(solidpixels);
        Mem_Free(alphapixels);
 }
@@ -1910,7 +1910,7 @@ static void Mod_Q1BSP_LoadTextures(sizebuf_t *sb)
                                                {
                                                        tx->width = image_width;
                                                        tx->height = image_height;
-                                                       skinframe = R_SkinFrame_LoadInternalBGRA(tx->name, TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP, pixels, image_width, image_height, true);
+                                                       skinframe = R_SkinFrame_LoadInternalBGRA(tx->name, TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP, pixels, image_width, image_height, image_width, image_height, CRC_Block(pixels, image_width * image_height * 4), true);
                                                }
                                                if (freepixels)
                                                        Mem_Free(freepixels);
@@ -1924,9 +1924,9 @@ static void Mod_Q1BSP_LoadTextures(sizebuf_t *sb)
                        }
                        // LordHavoc: some Tenebrae textures get replaced by black
                        if (!strncmp(tx->name, "*glassmirror", 12)) // Tenebrae
-                               tx->materialshaderpass->skinframes[0] = R_SkinFrame_LoadInternalBGRA(tx->name, TEXF_MIPMAP | TEXF_ALPHA, zerotrans, 1, 1, false);
+                               tx->materialshaderpass->skinframes[0] = R_SkinFrame_LoadInternalBGRA(tx->name, TEXF_MIPMAP | TEXF_ALPHA, zerotrans, 1, 1, 0, 0, 0, false);
                        else if (!strncmp(tx->name, "mirror", 6)) // Tenebrae
-                               tx->materialshaderpass->skinframes[0] = R_SkinFrame_LoadInternalBGRA(tx->name, 0, zeroopaque, 1, 1, false);
+                               tx->materialshaderpass->skinframes[0] = R_SkinFrame_LoadInternalBGRA(tx->name, 0, zeroopaque, 1, 1, 0, 0, 0, false);
                        tx->currentskinframe = tx->materialshaderpass->skinframes[0];
                }
 
@@ -2587,7 +2587,7 @@ static void Mod_Q1BSP_LoadFaces(sizebuf_t *sb)
                totaltris += numedges - 2;
        }
 
-       Mod_AllocSurfMesh(loadmodel->mempool, totalverts, totaltris, true, false, false);
+       Mod_AllocSurfMesh(loadmodel->mempool, totalverts, totaltris, true, false);
 
        lightmaptexture = NULL;
        deluxemaptexture = r_texture_blanknormalmap;
@@ -3852,31 +3852,6 @@ static void Mod_Q1BSP_RoundUpToHullSize(dp_model_t *cmodel, const vec3_t inmins,
        VectorAdd(inmins, hull->clip_size, outmaxs);
 }
 
-static int Mod_Q1BSP_CreateShadowMesh(dp_model_t *mod)
-{
-       int j;
-       int numshadowmeshtriangles = 0;
-       msurface_t *surface;
-       if (cls.state == ca_dedicated)
-               return 0;
-       // make a single combined shadow mesh to allow optimized shadow volume creation
-
-       for (j = 0, surface = mod->data_surfaces;j < mod->num_surfaces;j++, surface++)
-       {
-               surface->num_firstshadowmeshtriangle = numshadowmeshtriangles;
-               numshadowmeshtriangles += surface->num_triangles;
-       }
-       mod->brush.shadowmesh = Mod_ShadowMesh_Begin(mod->mempool, numshadowmeshtriangles * 3, numshadowmeshtriangles, NULL, NULL, NULL, false, false, true);
-       for (j = 0, surface = mod->data_surfaces;j < mod->num_surfaces;j++, surface++)
-               if (surface->num_triangles > 0)
-                       Mod_ShadowMesh_AddMesh(mod->mempool, mod->brush.shadowmesh, NULL, NULL, NULL, mod->surfmesh.data_vertex3f, NULL, NULL, NULL, NULL, surface->num_triangles, (mod->surfmesh.data_element3i + 3 * surface->num_firsttriangle));
-       mod->brush.shadowmesh = Mod_ShadowMesh_Finish(mod->mempool, mod->brush.shadowmesh, false, r_enableshadowvolumes.integer != 0, false);
-       if (mod->brush.shadowmesh && mod->brush.shadowmesh->neighbor3i)
-               Mod_BuildTriangleNeighbors(mod->brush.shadowmesh->neighbor3i, mod->brush.shadowmesh->element3i, mod->brush.shadowmesh->numtriangles);
-
-       return numshadowmeshtriangles;
-}
-
 void Mod_CollisionBIH_TraceLineAgainstSurfaces(dp_model_t *model, const frameblend_t *frameblend, const skeleton_t *skeleton, trace_t *trace, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
 
 void Mod_Q1BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
@@ -3986,8 +3961,6 @@ void Mod_Q1BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
        mod->GetLightInfo = R_Q1BSP_GetLightInfo;
        mod->CompileShadowMap = R_Q1BSP_CompileShadowMap;
        mod->DrawShadowMap = R_Q1BSP_DrawShadowMap;
-       mod->CompileShadowVolume = R_Q1BSP_CompileShadowVolume;
-       mod->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
        mod->DrawLight = R_Q1BSP_DrawLight;
 
 // load into heap
@@ -4043,9 +4016,6 @@ void Mod_Q1BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
        mod->numframes = 2;             // regular and alternate animation
        mod->numskins = 1;
 
-       // make a single combined shadow mesh to allow optimized shadow volume creation
-       Mod_Q1BSP_CreateShadowMesh(loadmodel);
-
        if (loadmodel->brush.numsubmodels)
                loadmodel->brush.submodels = (dp_model_t **)Mem_Alloc(loadmodel->mempool, loadmodel->brush.numsubmodels * sizeof(dp_model_t *));
 
@@ -4969,8 +4939,6 @@ static void Mod_Q2BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
        mod->GetLightInfo = R_Q1BSP_GetLightInfo;
        mod->CompileShadowMap = R_Q1BSP_CompileShadowMap;
        mod->DrawShadowMap = R_Q1BSP_DrawShadowMap;
-       mod->CompileShadowVolume = R_Q1BSP_CompileShadowVolume;
-       mod->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
        mod->DrawLight = R_Q1BSP_DrawLight;
 
 // load into heap
@@ -5031,9 +4999,6 @@ static void Mod_Q2BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
        mod->numframes = 0;             // q2bsp animations are kind of special, frame is unbounded...
        mod->numskins = 1;
 
-       // make a single combined shadow mesh to allow optimized shadow volume creation
-       Mod_Q1BSP_CreateShadowMesh(loadmodel);
-
        if (loadmodel->brush.numsubmodels)
                loadmodel->brush.submodels = (dp_model_t **)Mem_Alloc(loadmodel->mempool, loadmodel->brush.numsubmodels * sizeof(dp_model_t *));
 
@@ -5938,7 +5903,6 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
        int i, oldi, j, n, count, invalidelements, patchsize[2], finalwidth, finalheight, xtess, ytess, finalvertices, finaltriangles, firstvertex, firstelement, type, oldnumtriangles, oldnumtriangles2, meshvertices, meshtriangles, collisionvertices, collisiontriangles, numvertices, numtriangles, cxtess, cytess;
        float lightmaptcbase[2], lightmaptcscale[2];
        //int *originalelement3i;
-       //int *originalneighbor3i;
        float *originalvertex3f;
        //float *originalsvector3f;
        //float *originaltvector3f;
@@ -6158,7 +6122,7 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
        i = oldi;
        in = oldin;
        out = oldout;
-       Mod_AllocSurfMesh(loadmodel->mempool, meshvertices, meshtriangles, false, true, false);
+       Mod_AllocSurfMesh(loadmodel->mempool, meshvertices, meshtriangles, false, true);
        if (collisiontriangles)
        {
                loadmodel->brush.data_collisionvertex3f = (float *)Mem_Alloc(loadmodel->mempool, collisionvertices * sizeof(float[3]));
@@ -6723,23 +6687,9 @@ static void Mod_Q3BSP_LightPoint(dp_model_t *model, const vec3_t p, vec3_t ambie
        q3dlightgrid_t *a, *s;
 
        // scale lighting by lightstyle[0] so that darkmode in dpmod works properly
-       switch(vid.renderpath)
-       {
-       case RENDERPATH_GL20:
-       case RENDERPATH_D3D9:
-       case RENDERPATH_D3D10:
-       case RENDERPATH_D3D11:
-       case RENDERPATH_SOFT:
-       case RENDERPATH_GLES2:
-               // LordHavoc: FIXME: is this true?
-               stylescale = 1; // added while render
-               break;
-       case RENDERPATH_GL11:
-       case RENDERPATH_GL13:
-       case RENDERPATH_GLES1:
-               stylescale = r_refdef.scene.rtlightstylevalue[0];
-               break;
-       }
+       // LadyHavoc: FIXME: is this true?
+       stylescale = 1; // added while render
+       //stylescale = r_refdef.scene.rtlightstylevalue[0];
 
        if (!model->brushq3.num_lightgrid)
        {
@@ -7939,8 +7889,6 @@ static void Mod_Q3BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
        mod->GetLightInfo = R_Q1BSP_GetLightInfo;
        mod->CompileShadowMap = R_Q1BSP_CompileShadowMap;
        mod->DrawShadowMap = R_Q1BSP_DrawShadowMap;
-       mod->CompileShadowVolume = R_Q1BSP_CompileShadowVolume;
-       mod->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
        mod->DrawLight = R_Q1BSP_DrawLight;
 
        mod_base = (unsigned char *)header;
@@ -8015,9 +7963,6 @@ static void Mod_Q3BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
        // FIXME: shader alpha should replace r_wateralpha support in q3bsp
        loadmodel->brush.supportwateralpha = true;
 
-       // make a single combined shadow mesh to allow optimized shadow volume creation
-       Mod_Q1BSP_CreateShadowMesh(loadmodel);
-
        loadmodel->brush.num_leafs = 0;
        Mod_Q3BSP_RecursiveFindNumLeafs(loadmodel->brush.data_nodes);
 
@@ -8260,8 +8205,6 @@ void Mod_OBJ_Load(dp_model_t *mod, void *buffer, void *bufferend)
        loadmodel->GetLightInfo = R_Q1BSP_GetLightInfo;
        loadmodel->CompileShadowMap = R_Q1BSP_CompileShadowMap;
        loadmodel->DrawShadowMap = R_Q1BSP_DrawShadowMap;
-       loadmodel->CompileShadowVolume = R_Q1BSP_CompileShadowVolume;
-       loadmodel->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
        loadmodel->DrawLight = R_Q1BSP_DrawLight;
 
        skinfiles = Mod_LoadSkinFiles();
@@ -8597,14 +8540,12 @@ void Mod_OBJ_Load(dp_model_t *mod, void *buffer, void *bufferend)
        // allocate storage for final mesh data
        loadmodel->num_textures = numtextures * loadmodel->numskins;
        loadmodel->num_texturesperskin = numtextures;
-       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + numtriangles * sizeof(int[3]) + (numvertices <= 65536 ? numtriangles * sizeof(unsigned short[3]) : 0) + (r_enableshadowvolumes.integer ? numtriangles * sizeof(int[3]) : 0) + numvertices * sizeof(float[14]) + loadmodel->brush.numsubmodels * sizeof(dp_model_t *));
+       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + numtriangles * sizeof(int[3]) + (numvertices <= 65536 ? numtriangles * sizeof(unsigned short[3]) : 0) + numvertices * sizeof(float[14]) + loadmodel->brush.numsubmodels * sizeof(dp_model_t *));
        loadmodel->brush.submodels = (dp_model_t **)data;data += loadmodel->brush.numsubmodels * sizeof(dp_model_t *);
        loadmodel->sortedmodelsurfaces = (int *)data;data += loadmodel->num_surfaces * sizeof(int);
        loadmodel->data_textures = (texture_t *)data;data += loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t);
        loadmodel->surfmesh.num_vertices = numvertices;
        loadmodel->surfmesh.num_triangles = numtriangles;
-       if (r_enableshadowvolumes.integer)
-               loadmodel->surfmesh.data_neighbor3i = (int *)data;data += numtriangles * sizeof(int[3]);
        loadmodel->surfmesh.data_vertex3f = (float *)data;data += numvertices * sizeof(float[3]);
        loadmodel->surfmesh.data_svector3f = (float *)data;data += numvertices * sizeof(float[3]);
        loadmodel->surfmesh.data_tvector3f = (float *)data;data += numvertices * sizeof(float[3]);
@@ -8638,20 +8579,15 @@ void Mod_OBJ_Load(dp_model_t *mod, void *buffer, void *bufferend)
        Mem_Free(vertexhashtable);
        Mem_Free(vertexhashdata);
 
-       // make a single combined shadow mesh to allow optimized shadow volume creation
-       Mod_Q1BSP_CreateShadowMesh(loadmodel);
-
        // compute all the mesh information that was not loaded from the file
        if (loadmodel->surfmesh.data_element3s)
                for (i = 0;i < loadmodel->surfmesh.num_triangles*3;i++)
                        loadmodel->surfmesh.data_element3s[i] = loadmodel->surfmesh.data_element3i[i];
-       Mod_ValidateElements(loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles, 0, loadmodel->surfmesh.num_vertices, __FILE__, __LINE__);
+       Mod_ValidateElements(loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.data_element3s, loadmodel->surfmesh.num_triangles, 0, loadmodel->surfmesh.num_vertices, __FILE__, __LINE__);
        // generate normals if the file did not have them
        if (!VectorLength2(loadmodel->surfmesh.data_normal3f))
                Mod_BuildNormals(0, loadmodel->surfmesh.num_vertices, loadmodel->surfmesh.num_triangles, loadmodel->surfmesh.data_vertex3f, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.data_normal3f, r_smoothnormals_areaweighting.integer != 0);
        Mod_BuildTextureVectorsFromNormals(0, loadmodel->surfmesh.num_vertices, loadmodel->surfmesh.num_triangles, loadmodel->surfmesh.data_vertex3f, loadmodel->surfmesh.data_texcoordtexture2f, loadmodel->surfmesh.data_normal3f, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.data_svector3f, loadmodel->surfmesh.data_tvector3f, r_smoothnormals_areaweighting.integer != 0);
-       if (loadmodel->surfmesh.data_neighbor3i)
-               Mod_BuildTriangleNeighbors(loadmodel->surfmesh.data_neighbor3i, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles);
 
        // if this is a worldmodel and has no BSP tree, create a fake one for the purpose
        loadmodel->brush.num_visleafs = 1;