if (loadmodel->texturepool == NULL && cls.state != ca_dedicated)
loadmodel->texturepool = R_AllocTexturePool();
- power = loadmodel->brushq3.num_lightmapmergepower;
- power2 = power * 2;
- mask = (1 << power) - 1;
- for (i = 0;i < count;i++)
+ if (loadmodel->brushq3.num_lightmapmergepower > 0 || true)
{
- // figure out which merged lightmap texture this fits into
- int lightmapindex = i >> (loadmodel->brushq3.deluxemapping + power2);
- // if the lightmap has not been allocated yet, create it
- if (!loadmodel->brushq3.data_lightmaps[lightmapindex])
- {
- // create a lightmap only as large as necessary to hold the
- // remaining 128x128 blocks
- // if there are multiple merged lightmap textures then they will
- // all be full size except the last one which may be smaller
- // because it only needs to the remaining blocks, and it will often
- // be odd sizes like 2048x512 due to only being 25% full or so.
- j = (count >> loadmodel->brushq3.deluxemapping) - (lightmapindex << power2);
- for (mergewidth = 1;mergewidth < j && mergewidth < (1 << power);mergewidth *= 2)
- ;
- for (mergeheight = 1;mergewidth*mergeheight < j && mergeheight < (1 << power);mergeheight *= 2)
- ;
- Con_DPrintf("lightmap merge texture #%i is %ix%i (%i of %i used)\n", lightmapindex, mergewidth*128, mergeheight*128, min(j, mergewidth*mergeheight), mergewidth*mergeheight);
- loadmodel->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), mergewidth * 128, mergeheight * 128, NULL, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
- if (loadmodel->brushq3.data_deluxemaps)
- loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), mergewidth * 128, mergeheight * 128, NULL, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
- }
- mergewidth = R_TextureWidth(loadmodel->brushq3.data_lightmaps[lightmapindex]) / 128;
- mergeheight = R_TextureHeight(loadmodel->brushq3.data_lightmaps[lightmapindex]) / 128;
- j = i >> loadmodel->brushq3.deluxemapping;
- if (loadmodel->brushq3.deluxemapping && (i & 1))
- {
- if (loadmodel->brushq3.data_deluxemaps)
+ power = loadmodel->brushq3.num_lightmapmergepower;
+ power2 = power * 2;
+ mask = (1 << power) - 1;
+ for (i = 0;i < count;i++)
+ {
+ // figure out which merged lightmap texture this fits into
+ int lightmapindex = i >> (loadmodel->brushq3.deluxemapping + power2);
+ // if the lightmap has not been allocated yet, create it
+ if (!loadmodel->brushq3.data_lightmaps[lightmapindex])
+ {
+ // create a lightmap only as large as necessary to hold the
+ // remaining 128x128 blocks
+ // if there are multiple merged lightmap textures then they will
+ // all be full size except the last one which may be smaller
+ // because it only needs to the remaining blocks, and it will often
+ // be odd sizes like 2048x512 due to only being 25% full or so.
+ j = (count >> loadmodel->brushq3.deluxemapping) - (lightmapindex << power2);
+ for (mergewidth = 1;mergewidth < j && mergewidth < (1 << power);mergewidth *= 2)
+ ;
+ for (mergeheight = 1;mergewidth*mergeheight < j && mergeheight < (1 << power);mergeheight *= 2)
+ ;
+ Con_DPrintf("lightmap merge texture #%i is %ix%i (%i of %i used)\n", lightmapindex, mergewidth*128, mergeheight*128, min(j, mergewidth*mergeheight), mergewidth*mergeheight);
+ loadmodel->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), mergewidth * 128, mergeheight * 128, NULL, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
+ if (loadmodel->brushq3.data_deluxemaps)
+ loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), mergewidth * 128, mergeheight * 128, NULL, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
+ }
+ mergewidth = R_TextureWidth(loadmodel->brushq3.data_lightmaps[lightmapindex]) / 128;
+ mergeheight = R_TextureHeight(loadmodel->brushq3.data_lightmaps[lightmapindex]) / 128;
+ j = (i >> loadmodel->brushq3.deluxemapping) & ((1 << power2) - 1);
+ if (loadmodel->brushq3.deluxemapping && (i & 1))
R_UpdateTexture(loadmodel->brushq3.data_deluxemaps[lightmapindex], in[i].rgb, (j % mergewidth) * 128, (j / mergewidth) * 128, 128, 128);
+ else
+ R_UpdateTexture(loadmodel->brushq3.data_lightmaps [lightmapindex], in[i].rgb, (j % mergewidth) * 128, (j / mergewidth) * 128, 128, 128);
+ }
+ }
+ else
+ {
+ for (i = 0;i < count;i++)
+ {
+ // figure out which merged lightmap texture this fits into
+ int lightmapindex = i >> loadmodel->brushq3.deluxemapping;
+ if (loadmodel->brushq3.deluxemapping && (i & 1))
+ loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), 128, 128, in[i].rgb, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
+ else
+ loadmodel->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), 128, 128, in[i].rgb, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
}
- else
- R_UpdateTexture(loadmodel->brushq3.data_lightmaps [lightmapindex], in[i].rgb, (j % mergewidth) * 128, (j / mergewidth) * 128, 128, 128);
}
}
int lightmapindex = LittleLong(in->lightmapindex) >> loadmodel->brushq3.deluxemapping;
int mergewidth = R_TextureWidth(out->lightmaptexture) / 128;
int mergeheight = R_TextureHeight(out->lightmaptexture) / 128;
+ lightmapindex &= mergewidth * mergeheight - 1;
lightmaptcscale[0] = 1.0f / mergewidth;
lightmaptcscale[1] = 1.0f / mergeheight;
lightmaptcbase[0] = (lightmapindex % mergewidth) * lightmaptcscale[0];