X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=gl_rsurf.c;h=27cd761d4c08a0bf47eae9d796c7f1b47f190468;hb=fa02ab7e4877633fa6e2e30d5bcf2600aaafc7d3;hp=3d0b4c2d5fd086b5f081d648bf8ff40731a3a4ff;hpb=1d84e5d2c4212a98cc575ac1fce00160e53b6e62;p=xonotic%2Fdarkplaces.git diff --git a/gl_rsurf.c b/gl_rsurf.c index 3d0b4c2d..27cd761d 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -223,7 +223,8 @@ void R_UpdateLightmap(msurface_t *s, int lnum) { int smax, tmax; // upload the new lightmap texture fragment - glBindTexture(GL_TEXTURE_2D, lightmap_textures + lnum); + if(r_upload.value) + glBindTexture(GL_TEXTURE_2D, lightmap_textures + lnum); if (nosubimage || nosubimagefragments) { if (lightmapupdate[lnum][0] > s->light_t) @@ -242,12 +243,14 @@ void R_UpdateLightmap(msurface_t *s, int lnum) if (lightmaprgba) { R_BuildLightMap (s, templight, smax * 4); - glTexSubImage2D(GL_TEXTURE_2D, 0, s->light_s, s->light_t, smax, tmax, GL_RGBA, GL_UNSIGNED_BYTE, templight); + if(r_upload.value) + glTexSubImage2D(GL_TEXTURE_2D, 0, s->light_s, s->light_t, smax, tmax, GL_RGBA, GL_UNSIGNED_BYTE, templight); } else { R_BuildLightMap (s, templight, smax * 3); - glTexSubImage2D(GL_TEXTURE_2D, 0, s->light_s, s->light_t, smax, tmax, GL_RGB , GL_UNSIGNED_BYTE, templight); + if(r_upload.value) + glTexSubImage2D(GL_TEXTURE_2D, 0, s->light_s, s->light_t, smax, tmax, GL_RGB , GL_UNSIGNED_BYTE, templight); } } } @@ -331,20 +334,23 @@ void UploadLightmaps() { if (lightmapupdate[i][0] < lightmapupdate[i][1]) { - glBindTexture(GL_TEXTURE_2D, lightmap_textures + i); - if (nosubimage) + if(r_upload.value) { - if (lightmaprgba) - glTexImage2D(GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, lightmaps[i]); - else - glTexImage2D(GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, lightmaps[i]); - } - else - { - if (lightmaprgba) - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, lightmapupdate[i][0], BLOCK_WIDTH, lightmapupdate[i][1] - lightmapupdate[i][0], GL_RGBA, GL_UNSIGNED_BYTE, lightmaps[i] + (BLOCK_WIDTH * 4 * lightmapupdate[i][0])); + glBindTexture(GL_TEXTURE_2D, lightmap_textures + i); + if (nosubimage) + { + if (lightmaprgba) + glTexImage2D(GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, lightmaps[i]); + else + glTexImage2D(GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, lightmaps[i]); + } else - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, lightmapupdate[i][0], BLOCK_WIDTH, lightmapupdate[i][1] - lightmapupdate[i][0], GL_RGB, GL_UNSIGNED_BYTE, lightmaps[i] + (BLOCK_WIDTH * 3 * lightmapupdate[i][0])); + { + if (lightmaprgba) + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, lightmapupdate[i][0], BLOCK_WIDTH, lightmapupdate[i][1] - lightmapupdate[i][0], GL_RGBA, GL_UNSIGNED_BYTE, lightmaps[i] + (BLOCK_WIDTH * 4 * lightmapupdate[i][0])); + else + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, lightmapupdate[i][0], BLOCK_WIDTH, lightmapupdate[i][1] - lightmapupdate[i][0], GL_RGB, GL_UNSIGNED_BYTE, lightmaps[i] + (BLOCK_WIDTH * 3 * lightmapupdate[i][0])); + } } } lightmapupdate[i][0] = BLOCK_HEIGHT; @@ -469,8 +475,14 @@ void RSurf_DrawWater(msurface_t *s, texture_t *t, int transform, int alpha) } } -void RSurf_CheckLightmap(msurface_t *s) +void RSurf_DrawWall(msurface_t *s, texture_t *t, int transform) { + int i, lit = false, polys = 0, verts = 0; + float *v, *wv; + glpoly_t *p; + wallpoly_t *wp; + wallvert_t *out; + // check for lightmap modification if (r_dynamic.value) { if (r_ambient.value != s->cached_ambient || lighthalf != s->cached_lighthalf @@ -480,13 +492,8 @@ void RSurf_CheckLightmap(msurface_t *s) || (s->styles[3] != 255 && d_lightstylevalue[s->styles[3]] != s->cached_light[3])) R_UpdateLightmap(s, s->lightmaptexturenum); } -} - -void RSurf_Transform(glpoly_t *p, int transform) -{ - int i; - float *v, *wv = wvert; - for (;p;p = p->next) + wv = wvert; + for (p = s->polys;p;p = p->next) { for (i = 0, v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE) { @@ -497,30 +504,27 @@ void RSurf_Transform(glpoly_t *p, int transform) wv[3] = wv[4] = wv[5] = 0.0f; wv += 6; } + verts += p->numverts; + polys++; } -} - -void RSurf_EmitWallpolys(int lightmap, glpoly_t *p, texture_t *t, int lit) -{ - int i; - float *v, *wv = wvert; - wallpoly_t *wp = &wallpoly[currentwallpoly]; - wallvert_t *out = &wallvert[currentwallvert]; - for (;p;p = p->next) + if ((currentwallpoly + polys > MAX_WALLPOLYS) || (currentwallvert+verts > MAX_WALLVERTS)) + return; + if (s->dlightframe == r_dlightframecount && r_dynamic.value) + lit = RSurf_Light(s->dlightbits, s->polys); + wv = wvert; + wp = &wallpoly[currentwallpoly]; + out = &wallvert[currentwallvert]; + currentwallpoly += polys; + for (p = s->polys;p;p = p->next) { - if (currentwallpoly >= MAX_WALLPOLYS) - break; - if (currentwallvert+p->numverts > MAX_WALLVERTS) - break; v = p->verts[0]; wp->texnum = (unsigned short) t->gl_texturenum; - wp->lighttexnum = (unsigned short) lightmap; + wp->lighttexnum = (unsigned short) (lightmap_textures + s->lightmaptexturenum); wp->glowtexnum = (unsigned short) t->gl_glowtexturenum; wp->firstvert = currentwallvert; wp->numverts = p->numverts; wp->lit = lit; wp++; - currentwallpoly++; currentwallvert += p->numverts; for (i = 0;i < p->numverts;i++, v += VERTEXSIZE, wv += 6, out++) { @@ -552,57 +556,17 @@ void RSurf_EmitWallpolys(int lightmap, glpoly_t *p, texture_t *t, int lit) } } -void RSurf_DrawWall(msurface_t *s, texture_t *t, int transform) -{ - int lit = false; - // check for lightmap modification - RSurf_CheckLightmap(s); - RSurf_Transform(s->polys, transform); - if (s->dlightframe == r_dlightframecount && r_dynamic.value) - lit = RSurf_Light(s->dlightbits, s->polys); - RSurf_EmitWallpolys(lightmap_textures + s->lightmaptexturenum, s->polys, t, lit); -} - // LordHavoc: transparent brush models extern int r_dlightframecount; extern float modelalpha; -void RSurf_EmitWallVertex(glpoly_t *p, texture_t *t, int modulate, int alpha) -{ - int i; - float *v, *wv = wvert; - if (modulate) - { - for (;p;p = p->next) - { - v = p->verts[0]; - transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); - for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) - transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], wv[3] * currententity->colormod[0], wv[4] * currententity->colormod[1], wv[5] * currententity->colormod[2], alpha); - transpolyend(); - } - } - else - { - for (;p;p = p->next) - { - v = p->verts[0]; - transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); - for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) - transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], wv[3], wv[4], wv[5], alpha); - transpolyend(); - } - } -} - -void RSurf_WallVertexTransform(msurface_t *s, texture_t *t, int transform) +void RSurf_DrawWallVertex(msurface_t *s, texture_t *t, int transform, int isbmodel) { - int i; - glpoly_t *p; - float *wv, *v; - int size3; - float scale; - byte *lm; + int i, alpha, size3; + float *v, *wv, scale; + glpoly_t *p; + byte *lm; + alpha = (int) (modelalpha * 255.0f); size3 = ((s->extents[0]>>4)+1)*((s->extents[1]>>4)+1)*3; // *3 for colored lighting wv = wvert; for (p = s->polys;p;p = p->next) @@ -634,14 +598,31 @@ void RSurf_WallVertexTransform(msurface_t *s, texture_t *t, int transform) wv += 6; } } -} - -void RSurf_DrawWallVertex(msurface_t *s, texture_t *t, int transform, int isbmodel) -{ - RSurf_WallVertexTransform(s, t, transform); if (s->dlightframe == r_dlightframecount && r_dynamic.value) RSurf_Light(s->dlightbits, s->polys); - RSurf_EmitWallVertex(s->polys, t, isbmodel && (currententity->colormod[0] != 1 || currententity->colormod[1] != 1 || currententity->colormod[2] != 1), (int) (modelalpha * 255.0f)); + wv = wvert; + if (isbmodel && (currententity->colormod[0] != 1 || currententity->colormod[1] != 1 || currententity->colormod[2] != 1)) + { + for (p = s->polys;p;p = p->next) + { + v = p->verts[0]; + transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); + for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) + transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], wv[3] * currententity->colormod[0], wv[4] * currententity->colormod[1], wv[5] * currententity->colormod[2], alpha); + transpolyend(); + } + } + else + { + for (p = s->polys;p;p = p->next) + { + v = p->verts[0]; + transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); + for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) + transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], wv[3], wv[4], wv[5], alpha); + transpolyend(); + } + } } /* @@ -1001,14 +982,9 @@ void R_DrawWorld (void) if (cl.worldmodel) R_WorldNode (); - glClear (GL_DEPTH_BUFFER_BIT); - R_PushDlights (); // now mark the lit surfaces DrawTextureChains (); - - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } @@ -1116,13 +1092,16 @@ int AllocBlock (int w, int h, short *x, short *y) { byte blank[BLOCK_WIDTH*BLOCK_HEIGHT*3]; memset(blank, 0, sizeof(blank)); - glBindTexture(GL_TEXTURE_2D, lightmap_textures + texnum); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - if (lightmaprgba) - glTexImage2D (GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, blank); - else - glTexImage2D (GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, blank); + if(r_upload.value) + { + glBindTexture(GL_TEXTURE_2D, lightmap_textures + texnum); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + if (lightmaprgba) + glTexImage2D (GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, blank); + else + glTexImage2D (GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, blank); + } } for (i=0 ; ilight_s, surf->light_t, smax, tmax, GL_RGBA, GL_UNSIGNED_BYTE, templight); + if(r_upload.value) + glTexSubImage2D(GL_TEXTURE_2D, 0, surf->light_s, surf->light_t, smax, tmax, GL_RGBA, GL_UNSIGNED_BYTE, templight); } else { R_BuildLightMap (surf, templight, smax * 3); - glTexSubImage2D(GL_TEXTURE_2D, 0, surf->light_s, surf->light_t, smax, tmax, GL_RGB , GL_UNSIGNED_BYTE, templight); + if(r_upload.value) + glTexSubImage2D(GL_TEXTURE_2D, 0, surf->light_s, surf->light_t, smax, tmax, GL_RGB , GL_UNSIGNED_BYTE, templight); } } @@ -1371,24 +1352,29 @@ void GL_BuildLightmaps (void) if (nosubimage || nosubimagefragments) { - if (gl_mtexable) - qglSelectTexture(gl_mtex_enum+1); + if(r_upload.value) + if (gl_mtexable) + qglSelectTexture(gl_mtex_enum+1); for (i = 0;i < MAX_LIGHTMAPS;i++) { if (!allocated[i][0]) break; lightmapupdate[i][0] = BLOCK_HEIGHT; lightmapupdate[i][1] = 0; - glBindTexture(GL_TEXTURE_2D, lightmap_textures + i); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - if (lightmaprgba) - glTexImage2D(GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, lightmaps[i]); - else - glTexImage2D(GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, lightmaps[i]); + if(r_upload.value) + { + glBindTexture(GL_TEXTURE_2D, lightmap_textures + i); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + if (lightmaprgba) + glTexImage2D(GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, lightmaps[i]); + else + glTexImage2D(GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, lightmaps[i]); + } } - if (gl_mtexable) - qglSelectTexture(gl_mtex_enum+0); + if(r_upload.value) + if (gl_mtexable) + qglSelectTexture(gl_mtex_enum+0); } }