]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
made darkplaces compile successfully with g++ to test for errors C doesn't care about...
[xonotic/darkplaces.git] / gl_rsurf.c
index b41e061efa6c0f0cf6d9ac40f47b34774435e946..bec9823d0c1ff40253730b34c4ebf4942f5bb971 100644 (file)
@@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 cvar_t r_ambient = {0, "r_ambient", "0"};
 cvar_t r_drawportals = {0, "r_drawportals", "0"};
 cvar_t r_testvis = {0, "r_testvis", "0"};
 cvar_t r_ambient = {0, "r_ambient", "0"};
 cvar_t r_drawportals = {0, "r_drawportals", "0"};
 cvar_t r_testvis = {0, "r_testvis", "0"};
-cvar_t r_detailtextures = {CVAR_SAVE, "r_detailtextures", "1"};
 cvar_t r_surfaceworldnode = {0, "r_surfaceworldnode", "0"};
 cvar_t r_drawcollisionbrushes_polygonfactor = {0, "r_drawcollisionbrushes_polygonfactor", "-1"};
 cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygonoffset", "0"};
 cvar_t r_surfaceworldnode = {0, "r_surfaceworldnode", "0"};
 cvar_t r_drawcollisionbrushes_polygonfactor = {0, "r_drawcollisionbrushes_polygonfactor", "-1"};
 cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygonoffset", "0"};
@@ -300,7 +299,7 @@ static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
        int i;
        float *v;
        rmeshstate_t m;
        int i;
        float *v;
        rmeshstate_t m;
-       const mportal_t *portal = calldata1;
+       const mportal_t *portal = (mportal_t *)calldata1;
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
        GL_DepthTest(true);
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
        GL_DepthTest(true);
@@ -657,12 +656,6 @@ void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
        *outnumsurfacespointer = info.outnumsurfaces;
 }
 
        *outnumsurfacespointer = info.outnumsurfaces;
 }
 
-extern float *rsurface_vertex3f;
-extern float *rsurface_svector3f;
-extern float *rsurface_tvector3f;
-extern float *rsurface_normal3f;
-extern void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t modelorg);
-
 void R_Q1BSP_CompileShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
 {
        model_t *model = ent->model;
 void R_Q1BSP_CompileShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
 {
        model_t *model = ent->model;
@@ -686,6 +679,12 @@ void R_Q1BSP_CompileShadowVolume(entity_render_t *ent, vec3_t relativelightorigi
        r_shadow_compilingrtlight->static_meshchain_shadow = Mod_ShadowMesh_Finish(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_shadow, false, false);
 }
 
        r_shadow_compilingrtlight->static_meshchain_shadow = Mod_ShadowMesh_Finish(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_shadow, false, false);
 }
 
+extern float *rsurface_vertex3f;
+extern float *rsurface_svector3f;
+extern float *rsurface_tvector3f;
+extern float *rsurface_normal3f;
+extern void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t modelorg);
+
 void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs)
 {
        model_t *model = ent->model;
 void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs)
 {
        model_t *model = ent->model;
@@ -735,26 +734,31 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
        }
 }
 
        }
 }
 
-void R_Q1BSP_DrawLight(entity_render_t *ent, float *lightcolorbase, int numsurfaces, const int *surfacelist)
+#define RSURF_MAX_BATCHSURFACES 1024
+
+void R_Q1BSP_DrawLight(entity_render_t *ent, float *lightcolorbase, float *lightcolorpants, float *lightcolorshirt, int numsurfaces, const int *surfacelist)
 {
        model_t *model = ent->model;
        msurface_t *surface;
        texture_t *texture;
 {
        model_t *model = ent->model;
        msurface_t *surface;
        texture_t *texture;
-       int surfacelistindex;
+       int surfacelistindex, batchnumsurfaces;
+       msurface_t *batchsurfacelist[RSURF_MAX_BATCHSURFACES];
        vec3_t modelorg;
        texture_t *tex;
        vec3_t modelorg;
        texture_t *tex;
-       vec3_t lightcolorpants, lightcolorshirt;
        rtexture_t *basetexture = NULL;
        rtexture_t *glosstexture = NULL;
        float specularscale = 0;
        qboolean skip;
        if (r_drawcollisionbrushes.integer >= 2)
                return;
        rtexture_t *basetexture = NULL;
        rtexture_t *glosstexture = NULL;
        float specularscale = 0;
        qboolean skip;
        if (r_drawcollisionbrushes.integer >= 2)
                return;
+       if (VectorLength2(lightcolorbase) + VectorLength2(lightcolorpants) + VectorLength2(lightcolorshirt) < 0.0001)
+               return;
        R_UpdateAllTextureInfo(ent);
        Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
        tex = NULL;
        texture = NULL;
        skip = false;
        R_UpdateAllTextureInfo(ent);
        Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
        tex = NULL;
        texture = NULL;
        skip = false;
+       batchnumsurfaces = 0;
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                if ((ent == r_refdef.worldentity && !r_worldsurfacevisible[surfacelist[surfacelistindex]]))
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                if ((ent == r_refdef.worldentity && !r_worldsurfacevisible[surfacelist[surfacelistindex]]))
@@ -762,6 +766,11 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, float *lightcolorbase, int numsurfa
                surface = model->data_surfaces + surfacelist[surfacelistindex];
                if (tex != surface->texture)
                {
                surface = model->data_surfaces + surfacelist[surfacelistindex];
                if (tex != surface->texture)
                {
+                       if (batchnumsurfaces > 0)
+                       {
+                               R_Shadow_RenderSurfacesLighting(ent, texture, batchnumsurfaces, batchsurfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, basetexture, texture->skin.pants, texture->skin.shirt, texture->skin.nmap, glosstexture, specularscale, modelorg);
+                               batchnumsurfaces = 0;
+                       }
                        tex = surface->texture;
                        texture = surface->texture->currentframe;
                        // FIXME: transparent surfaces need to be lit later
                        tex = surface->texture;
                        texture = surface->texture->currentframe;
                        // FIXME: transparent surfaces need to be lit later
@@ -790,46 +799,24 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, float *lightcolorbase, int numsurfa
                                        specularscale = r_shadow_rtlight->specularscale * r_shadow_gloss2intensity.value;
                                }
                        }
                                        specularscale = r_shadow_rtlight->specularscale * r_shadow_gloss2intensity.value;
                                }
                        }
-                       VectorClear(lightcolorpants);
-                       VectorClear(lightcolorshirt);
-                       if (ent->colormap >= 0)
-                       {
-                               // 128-224 are backwards ranges
-                               int b = (ent->colormap & 0xF) << 4;b += (b >= 128 && b < 224) ? 4 : 12;
-                               if (texture->skin.pants && b < 224)
-                               {
-                                       qbyte *bcolor = (qbyte *) (&palette_complete[b]);
-                                       lightcolorpants[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
-                                       lightcolorpants[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
-                                       lightcolorpants[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
-                               }
-                               // 128-224 are backwards ranges
-                               b = (ent->colormap & 0xF0);b += (b >= 128 && b < 224) ? 4 : 12;
-                               if (texture->skin.shirt && b < 224)
-                               {
-                                       qbyte *bcolor = (qbyte *) (&palette_complete[b]);
-                                       lightcolorshirt[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
-                                       lightcolorshirt[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
-                                       lightcolorshirt[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
-                               }
-                               basetexture = texture->skin.base;
-                       }
-                       else
-                               basetexture = texture->skin.merged ? texture->skin.merged : texture->skin.base;
+                       basetexture = (ent->colormap < 0 && texture->skin.merged) ? texture->skin.merged : texture->skin.base;
                        if ((r_shadow_rtlight->ambientscale + r_shadow_rtlight->diffusescale) * (VectorLength2(lightcolorbase) + VectorLength2(lightcolorpants) + VectorLength2(lightcolorshirt)) + specularscale * VectorLength2(lightcolorbase) < (1.0f / 1048576.0f))
                                skip = true;
                }
                        if ((r_shadow_rtlight->ambientscale + r_shadow_rtlight->diffusescale) * (VectorLength2(lightcolorbase) + VectorLength2(lightcolorpants) + VectorLength2(lightcolorshirt)) + specularscale * VectorLength2(lightcolorbase) < (1.0f / 1048576.0f))
                                skip = true;
                }
-               if (skip || !surface->num_triangles)
-                       continue;
-               RSurf_SetVertexPointer(ent, texture, surface, modelorg);
-               if (!rsurface_svector3f)
+               if (!skip && surface->num_triangles)
                {
                {
-                       rsurface_svector3f = varray_svector3f;
-                       rsurface_tvector3f = varray_tvector3f;
-                       rsurface_normal3f = varray_normal3f;
-                       Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
+                       if (batchnumsurfaces == RSURF_MAX_BATCHSURFACES)
+                       {
+                               R_Shadow_RenderSurfacesLighting(ent, texture, batchnumsurfaces, batchsurfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, basetexture, texture->skin.pants, texture->skin.shirt, texture->skin.nmap, glosstexture, specularscale, modelorg);
+                               batchnumsurfaces = 0;
+                       }
+                       batchsurfacelist[batchnumsurfaces++] = surface;
                }
                }
-               R_Shadow_RenderLighting(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle), rsurface_vertex3f, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, surface->groupmesh->data_texcoordtexture2f, lightcolorbase, lightcolorpants, lightcolorshirt, basetexture, texture->skin.pants, texture->skin.shirt, texture->skin.nmap, texture->skin.gloss, specularscale);
+       }
+       if (batchnumsurfaces > 0)
+       {
+               R_Shadow_RenderSurfacesLighting(ent, texture, batchnumsurfaces, batchsurfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, basetexture, texture->skin.pants, texture->skin.shirt, texture->skin.nmap, glosstexture, specularscale, modelorg);
+               batchnumsurfaces = 0;
        }
        qglEnable(GL_CULL_FACE);
 }
        }
        qglEnable(GL_CULL_FACE);
 }
@@ -854,7 +841,6 @@ void GL_Surf_Init(void)
        Cvar_RegisterVariable(&r_ambient);
        Cvar_RegisterVariable(&r_drawportals);
        Cvar_RegisterVariable(&r_testvis);
        Cvar_RegisterVariable(&r_ambient);
        Cvar_RegisterVariable(&r_drawportals);
        Cvar_RegisterVariable(&r_testvis);
-       Cvar_RegisterVariable(&r_detailtextures);
        Cvar_RegisterVariable(&r_surfaceworldnode);
        Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonfactor);
        Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset);
        Cvar_RegisterVariable(&r_surfaceworldnode);
        Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonfactor);
        Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset);