]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
commandmode: use Cmd_ExecuteString so semicolons don't start new commands
[xonotic/darkplaces.git] / gl_rmain.c
index 03beaffe470fa3224954d56b51c54b26a46af93f..5aa039e08de154240f9ca3dad4a3c301a5f66319 100644 (file)
@@ -1907,7 +1907,7 @@ skinframe_t *R_SkinFrame_Find(const char *name, int textureflags, int comparewid
 
 #define R_SKINFRAME_LOAD_AVERAGE_COLORS(cnt, getpixel) \
        { \
-               unsigned long avgcolor[5], wsum; \
+               unsigned long long avgcolor[5], wsum; \
                int pix, comp, w; \
                avgcolor[0] = 0; \
                avgcolor[1] = 0; \
@@ -1918,23 +1918,25 @@ skinframe_t *R_SkinFrame_Find(const char *name, int textureflags, int comparewid
                for(pix = 0; pix < cnt; ++pix) \
                { \
                        w = 0; \
-                       for(comp = 0; comp < 4; ++comp) \
+                       for(comp = 0; comp < 3; ++comp) \
                                w += getpixel; \
                        if(w) /* ignore perfectly black pixels because that is better for model skins */ \
                        { \
                                ++wsum; \
-                               for(comp = 0; comp < 4; ++comp) \
-                                       avgcolor[comp] += (w = getpixel); \
+                               /* comp = 3; -- not needed, comp is always 3 when we get here */ \
+                               w = getpixel; \
+                               for(comp = 0; comp < 3; ++comp) \
+                                       avgcolor[comp] += getpixel * w; \
+                               avgcolor[3] += w; \
                        } \
-                       avgcolor[4] += w; \
+                       /* comp = 3; -- not needed, comp is always 3 when we get here */ \
+                       avgcolor[4] += getpixel; \
                } \
-               if(avgcolor[3] == 0) /* just fully transparent pixels seen? bad luck... */ \
-                       avgcolor[3] = 255 * wsum; \
                if(avgcolor[3] == 0) /* no pixels seen? even worse */ \
                        avgcolor[3] = 1; \
-               skinframe->avgcolor[0] = avgcolor[2] / (1.0 * avgcolor[3]); \
-               skinframe->avgcolor[1] = avgcolor[1] / (1.0 * avgcolor[3]); \
-               skinframe->avgcolor[2] = avgcolor[0] / (1.0 * avgcolor[3]); \
+               skinframe->avgcolor[0] = avgcolor[2] / (255.0 * avgcolor[3]); \
+               skinframe->avgcolor[1] = avgcolor[1] / (255.0 * avgcolor[3]); \
+               skinframe->avgcolor[2] = avgcolor[0] / (255.0 * avgcolor[3]); \
                skinframe->avgcolor[3] = avgcolor[4] / (255.0 * cnt); \
        }
 
@@ -2014,6 +2016,7 @@ skinframe_t *R_SkinFrame_LoadExternal_CheckAlpha(const char *name, int texturefl
        }
 
        R_SKINFRAME_LOAD_AVERAGE_COLORS(basepixels_width * basepixels_height, basepixels[4 * pix + comp]);
+       //Con_Printf("Texture %s has average colors %f %f %f alpha %f\n", name, skinframe->avgcolor[0], skinframe->avgcolor[1], skinframe->avgcolor[2], skinframe->avgcolor[3]);
 
        // _norm is the name used by tenebrae and has been adopted as standard
        if (loadnormalmap)
@@ -2132,6 +2135,7 @@ skinframe_t *R_SkinFrame_LoadInternalBGRA(const char *name, int textureflags, co
        }
 
        R_SKINFRAME_LOAD_AVERAGE_COLORS(width * height, skindata[4 * pix + comp]);
+       //Con_Printf("Texture %s has average colors %f %f %f alpha %f\n", name, skinframe->avgcolor[0], skinframe->avgcolor[1], skinframe->avgcolor[2], skinframe->avgcolor[3]);
 
        return skinframe;
 }
@@ -2140,6 +2144,7 @@ skinframe_t *R_SkinFrame_LoadInternalQuake(const char *name, int textureflags, i
 {
        int i;
        unsigned char *temp1, *temp2;
+       unsigned int *palette;
        skinframe_t *skinframe;
 
        if (cls.state == ca_dedicated)
@@ -2150,6 +2155,8 @@ skinframe_t *R_SkinFrame_LoadInternalQuake(const char *name, int textureflags, i
        if (skinframe && skinframe->base)
                return skinframe;
 
+       palette = (loadglowtexture ? palette_bgra_nofullbrights : ((skinframe->textureflags & TEXF_ALPHA) ? palette_bgra_transparent : palette_bgra_complete));
+
        skinframe->stain = NULL;
        skinframe->merged = NULL;
        skinframe->base = r_texture_notexture;
@@ -2178,7 +2185,7 @@ skinframe_t *R_SkinFrame_LoadInternalQuake(const char *name, int textureflags, i
                Mem_Free(temp1);
        }
        // use either a custom palette, or the quake palette
-       skinframe->base = skinframe->merged = R_SkinFrame_TextureForSkinLayer(skindata, width, height, va("%s_merged", skinframe->basename), (loadglowtexture ? palette_bgra_nofullbrights : ((skinframe->textureflags & TEXF_ALPHA) ? palette_bgra_transparent : palette_bgra_complete)), skinframe->textureflags, true); // all
+       skinframe->base = skinframe->merged = R_SkinFrame_TextureForSkinLayer(skindata, width, height, va("%s_merged", skinframe->basename), palette, skinframe->textureflags, true); // all
        if (loadglowtexture)
                skinframe->glow = R_SkinFrame_TextureForSkinLayer(skindata, width, height, va("%s_glow", skinframe->basename), palette_bgra_onlyfullbrights, skinframe->textureflags, false); // glow
        if (loadpantsandshirt)
@@ -2197,7 +2204,8 @@ skinframe_t *R_SkinFrame_LoadInternalQuake(const char *name, int textureflags, i
                        skinframe->fog = R_SkinFrame_TextureForSkinLayer(skindata, width, height, va("%s_fog", skinframe->basename), palette_bgra_alpha, skinframe->textureflags, true); // fog mask
        }
 
-       R_SKINFRAME_LOAD_AVERAGE_COLORS(width * height, ((unsigned char *)palette_bgra_alpha)[skindata[pix]*4 + comp]);
+       R_SKINFRAME_LOAD_AVERAGE_COLORS(width * height, ((unsigned char *)palette)[skindata[pix]*4 + comp]);
+       //Con_Printf("Texture %s has average colors %f %f %f alpha %f\n", name, skinframe->avgcolor[0], skinframe->avgcolor[1], skinframe->avgcolor[2], skinframe->avgcolor[3]);
 
        return skinframe;
 }
@@ -5729,17 +5737,15 @@ static void RSurf_DrawBatch_GL11_MakeFullbrightLightmapColorArray(int texturenum
 {
        int texturesurfaceindex;
        int i;
-       float f;
        float *v, *c2;
        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
        {
                const msurface_t *surface = texturesurfacelist[texturesurfaceindex];
                for (i = 0, v = (rsurface.vertex3f + 3 * surface->num_firstvertex), c2 = (rsurface.array_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c2 += 4)
                {
-                       f = FogPoint_Model(v);
-                       c2[0] = 1;
-                       c2[1] = 1;
-                       c2[2] = 1;
+                       c2[0] = 0.5;
+                       c2[1] = 0.5;
+                       c2[2] = 0.5;
                        c2[3] = 1;
                }
        }
@@ -5851,9 +5857,9 @@ static void RSurf_DrawBatch_GL11_ApplyAmbient(int texturenumsurfaces, msurface_t
                const msurface_t *surface = texturesurfacelist[texturesurfaceindex];
                for (i = 0, c = (rsurface.lightmapcolor4f + 4 * surface->num_firstvertex), c2 = (rsurface.array_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, c += 4, c2 += 4)
                {
-                       c2[0] = c[0] + r_refdef.scene.ambient / 64.0;
-                       c2[1] = c[1] + r_refdef.scene.ambient / 64.0;
-                       c2[2] = c[2] + r_refdef.scene.ambient / 64.0;
+                       c2[0] = c[0] + r_refdef.scene.ambient / 128.0;
+                       c2[1] = c[1] + r_refdef.scene.ambient / 128.0;
+                       c2[2] = c[2] + r_refdef.scene.ambient / 128.0;
                        c2[3] = c[3];
                }
        }
@@ -6458,9 +6464,9 @@ static void R_DrawTextureSurfaceList_ShowSurfaces3(int texturenumsurfaces, msurf
 
        if (rsurface.texture->currentskinframe->pants || rsurface.texture->currentskinframe->shirt)
        {
-               c[0] = (rsurface.colormap_pantscolor[0] * 0.3 + rsurface.colormap_shirtcolor[0] * 0.7);
-               c[1] = (rsurface.colormap_pantscolor[1] * 0.3 + rsurface.colormap_shirtcolor[1] * 0.7);
-               c[2] = (rsurface.colormap_pantscolor[2] * 0.3 + rsurface.colormap_shirtcolor[2] * 0.7);
+               c[0] = 0.5 * (rsurface.colormap_pantscolor[0] * 0.3 + rsurface.colormap_shirtcolor[0] * 0.7);
+               c[1] = 0.5 * (rsurface.colormap_pantscolor[1] * 0.3 + rsurface.colormap_shirtcolor[1] * 0.7);
+               c[2] = 0.5 * (rsurface.colormap_pantscolor[2] * 0.3 + rsurface.colormap_shirtcolor[2] * 0.7);
        }
 
        // brighten it up (as texture value 127 means "unlit")
@@ -6497,23 +6503,36 @@ static void R_DrawTextureSurfaceList_ShowSurfaces3(int texturenumsurfaces, msurf
                GL_DepthMask(writedepth);
        }
 
-       rsurface.lightmapcolor4f = rsurface.modellightmapcolor4f;
-       rsurface.lightmapcolor4f_bufferobject = rsurface.modellightmapcolor4f_bufferobject;
-       rsurface.lightmapcolor4f_bufferoffset = rsurface.modellightmapcolor4f_bufferoffset;
+       rsurface.lightmapcolor4f = NULL;
 
-       if (rsurface.texture->currentmaterialflags & MATERIALFLAG_MODELLIGHT)
+       if (rsurface.texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT)
+       {
+               RSurf_PrepareVerticesForBatch(false, false, texturenumsurfaces, texturesurfacelist);
+
+               rsurface.lightmapcolor4f = NULL;
+               rsurface.lightmapcolor4f_bufferobject = 0;
+               rsurface.lightmapcolor4f_bufferoffset = 0;
+       }
+       else if (rsurface.texture->currentmaterialflags & MATERIALFLAG_MODELLIGHT)
        {
                qboolean applycolor = true;
                float one = 1.0;
 
                RSurf_PrepareVerticesForBatch(true, false, texturenumsurfaces, texturesurfacelist);
+
                r_refdef.lightmapintensity = 1;
                RSurf_DrawBatch_GL11_ApplyVertexShade(texturenumsurfaces, texturesurfacelist, &one, &one, &one, &one, &applycolor);
                r_refdef.lightmapintensity = 0; // we're in showsurfaces, after all
        }
        else
+       {
                RSurf_PrepareVerticesForBatch(false, false, texturenumsurfaces, texturesurfacelist);
 
+               rsurface.lightmapcolor4f = rsurface.modellightmapcolor4f;
+               rsurface.lightmapcolor4f_bufferobject = rsurface.modellightmapcolor4f_bufferobject;
+               rsurface.lightmapcolor4f_bufferoffset = rsurface.modellightmapcolor4f_bufferoffset;
+       }
+
        if(!rsurface.lightmapcolor4f)
                RSurf_DrawBatch_GL11_MakeFullbrightLightmapColorArray(texturenumsurfaces, texturesurfacelist);