From: havoc Date: Mon, 26 May 2003 16:35:14 +0000 (+0000) Subject: added R_ScrollTexCoord2f (copies while texture coordinates with an offset) X-Git-Tag: xonotic-v0.1.0preview~6609 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9168bc2cbb2230dd8147be0b5aa31cf4a1404745;p=xonotic%2Fdarkplaces.git added R_ScrollTexCoord2f (copies while texture coordinates with an offset) added multitexture path to skysphere rendering (10% speed gain) and modified combine setup in gl_backend to support GL_INTERPOLATE_ARB behaving like GL_DECAL added support for gl_mesh_copyarrays 0 mode in skysphere rendering (1% speed gain) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3045 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_backend.c b/gl_backend.c index 3196022f..1ab98969 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -560,7 +560,7 @@ void GL_SetupTextureState(void) qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);CHECKGLERROR qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);CHECKGLERROR qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);CHECKGLERROR - qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT_ARB);CHECKGLERROR + qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_TEXTURE);CHECKGLERROR // for GL_INTERPOLATE_ARB mode qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);CHECKGLERROR qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);CHECKGLERROR qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);CHECKGLERROR @@ -1583,7 +1583,7 @@ void R_Mesh_CopyTexCoord2f(int tmu, const float *texcoord2f, int numverts) if (mesh_var) { float *out = varray_texcoord2f[tmu]; - while (--numverts) + while (numverts--) { *out++ = *texcoord2f++; *out++ = *texcoord2f++; @@ -1600,7 +1600,7 @@ void R_Mesh_CopyColor4f(const float *color4f, int numverts) if (mesh_var) { float *out = varray_color4f; - while (--numverts) + while (numverts--) { *out++ = *color4f++; *out++ = *color4f++; @@ -1613,6 +1613,15 @@ void R_Mesh_CopyColor4f(const float *color4f, int numverts) memcpy(varray_color4f, color4f, numverts * sizeof(float[4])); } +void R_ScrollTexCoord2f (float *out2f, const float *in2f, int numverts, float s, float t) +{ + while (numverts--) + { + *out2f++ = *in2f++ + s; + *out2f++ = *in2f++ + t; + } +} + //=========================================================================== // vertex array caching subsystem //=========================================================================== diff --git a/gl_backend.h b/gl_backend.h index 72acc7b2..83125962 100644 --- a/gl_backend.h +++ b/gl_backend.h @@ -92,6 +92,8 @@ void R_Mesh_CopyVertex3f(const float *vertex3f, int numverts); void R_Mesh_CopyTexCoord2f(int tmu, const float *texcoord2f, int numverts); // copies a color4f array into varray_color4f void R_Mesh_CopyColor4f(const float *color4f, int numverts); +// copies a texcoord2f array into another array, with scrolling +void R_ScrollTexCoord2f (float *out2f, const float *in2f, int numverts, float s, float t); // saves a section of the rendered frame to a .tga or .jpg file qboolean SCR_ScreenShot(char *filename, int x, int y, int width, int height, qboolean jpeg); diff --git a/r_sky.c b/r_sky.c index 312705c3..9a60d6d9 100644 --- a/r_sky.c +++ b/r_sky.c @@ -255,6 +255,7 @@ static void R_SkySphere(void) const float *in2f; static qboolean skysphereinitialized = false; rmeshstate_t m; + rcachearrayrequest_t request; if (!skysphereinitialized) { skysphereinitialized = true; @@ -266,40 +267,105 @@ static void R_SkySphere(void) // wrap the scroll just to be extra kind to float accuracy speedscale -= (int)speedscale; - memset(&m, 0, sizeof(m)); - m.blendfunc1 = GL_ONE; - m.blendfunc2 = GL_ZERO; - m.depthdisable = true; // don't modify or read zbuffer - m.tex[0] = R_GetTexture(solidskytexture); - R_Mesh_State(&m); - - GL_Color(r_colorscale, r_colorscale, r_colorscale, 1); - - R_Mesh_GetSpace(skysphere_numverts); - R_Mesh_CopyVertex3f(skysphere_vertex3f, skysphere_numverts); - for (i = 0, out2f = varray_texcoord2f[0], in2f = skysphere_texcoord2f;i < skysphere_numverts;i++) + if (r_colorscale == 1 && r_textureunits.integer >= 2) { - *out2f++ = *in2f++ + speedscale; - *out2f++ = *in2f++ + speedscale; + // one pass using GL_DECAL or GL_INTERPOLATE_ARB for alpha layer + // LordHavoc: note that color is not set here because it does not + // matter with GL_REPLACE + memset(&m, 0, sizeof(m)); + m.blendfunc1 = GL_ONE; + m.blendfunc2 = GL_ZERO; + m.depthdisable = true; // don't modify or read zbuffer + m.tex[0] = R_GetTexture(solidskytexture); + m.tex[1] = R_GetTexture(alphaskytexture); + m.texcombinergb[0] = GL_REPLACE; + m.texcombinergb[1] = gl_combine.integer ? GL_INTERPOLATE_ARB : GL_DECAL; + if (gl_mesh_copyarrays.integer) + { + R_Mesh_State(&m); + R_Mesh_GetSpace(skysphere_numverts); + R_Mesh_CopyVertex3f(skysphere_vertex3f, skysphere_numverts); + R_ScrollTexCoord2f(varray_texcoord2f[0], skysphere_texcoord2f, skysphere_numverts, speedscale, speedscale); + R_ScrollTexCoord2f(varray_texcoord2f[1], skysphere_texcoord2f, skysphere_numverts, speedscale*2, speedscale*2); + } + else + { + m.pointervertexcount = skysphere_numverts; + m.pointer_vertex = skysphere_vertex3f; + memset(&request, 0, sizeof(request)); + request.data_size = skysphere_numverts * sizeof(float[2]); + request.id_pointer1 = skysphere_texcoord2f; + request.id_number1 = CRC_Block((void *)&speedscale, sizeof(speedscale)); + if (R_Mesh_CacheArray(&request)) + R_ScrollTexCoord2f(request.data, skysphere_texcoord2f, skysphere_numverts, speedscale, speedscale); + m.pointer_texcoord[0] = request.data; + speedscale *= 2; + request.id_number1 = CRC_Block((void *)&speedscale, sizeof(speedscale)); + if (R_Mesh_CacheArray(&request)) + R_ScrollTexCoord2f(request.data, skysphere_texcoord2f, skysphere_numverts, speedscale, speedscale); + m.pointer_texcoord[1] = request.data; + R_Mesh_State(&m); + } + R_Mesh_Draw(skysphere_numverts, skysphere_numtriangles, skysphere_element3i); } - R_Mesh_Draw(skysphere_numverts, skysphere_numtriangles, skysphere_element3i); - - m.blendfunc1 = GL_SRC_ALPHA; - m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA; - m.tex[0] = R_GetTexture(alphaskytexture); - R_Mesh_State(&m); + else + { + // two pass + GL_Color(r_colorscale, r_colorscale, r_colorscale, 1); + memset(&m, 0, sizeof(m)); + m.blendfunc1 = GL_ONE; + m.blendfunc2 = GL_ZERO; + m.depthdisable = true; // don't modify or read zbuffer + m.tex[0] = R_GetTexture(solidskytexture); + if (gl_mesh_copyarrays.integer) + { + R_Mesh_State(&m); + R_Mesh_GetSpace(skysphere_numverts); + R_Mesh_CopyVertex3f(skysphere_vertex3f, skysphere_numverts); + R_ScrollTexCoord2f(varray_texcoord2f[0], skysphere_texcoord2f, skysphere_numverts, speedscale, speedscale); + } + else + { + m.pointervertexcount = skysphere_numverts; + m.pointer_vertex = skysphere_vertex3f; + memset(&request, 0, sizeof(request)); + request.data_size = skysphere_numverts * sizeof(float[2]); + request.id_pointer1 = skysphere_texcoord2f; + request.id_number1 = CRC_Block((void *)&speedscale, sizeof(speedscale)); + if (R_Mesh_CacheArray(&request)) + R_ScrollTexCoord2f(request.data, skysphere_texcoord2f, skysphere_numverts, speedscale, speedscale); + m.pointer_texcoord[0] = request.data; + R_Mesh_State(&m); + } + R_Mesh_Draw(skysphere_numverts, skysphere_numtriangles, skysphere_element3i); - // scroll the lower cloud layer twice as fast (just like quake did) - speedscale *= 2; + // scroll the lower cloud layer twice as fast (just like quake did) + speedscale *= 2; - R_Mesh_GetSpace(skysphere_numverts); - R_Mesh_CopyVertex3f(skysphere_vertex3f, skysphere_numverts); - for (i = 0, out2f = varray_texcoord2f[0], in2f = skysphere_texcoord2f;i < skysphere_numverts;i++) - { - *out2f++ = *in2f++ + speedscale; - *out2f++ = *in2f++ + speedscale; + m.blendfunc1 = GL_SRC_ALPHA; + m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA; + m.tex[0] = R_GetTexture(alphaskytexture); + if (gl_mesh_copyarrays.integer) + { + R_Mesh_State(&m); + R_Mesh_GetSpace(skysphere_numverts); + R_Mesh_CopyVertex3f(skysphere_vertex3f, skysphere_numverts); + R_ScrollTexCoord2f(varray_texcoord2f[0], skysphere_texcoord2f, skysphere_numverts, speedscale, speedscale); + } + else + { + m.pointervertexcount = skysphere_numverts; + m.pointer_vertex = skysphere_vertex3f; + request.data_size = skysphere_numverts * sizeof(float[2]); + request.id_pointer1 = skysphere_texcoord2f; + request.id_number1 = CRC_Block((void *)&speedscale, sizeof(speedscale)); + if (R_Mesh_CacheArray(&request)) + R_ScrollTexCoord2f(request.data, skysphere_texcoord2f, skysphere_numverts, speedscale, speedscale); + m.pointer_texcoord[0] = request.data; + R_Mesh_State(&m); + } + R_Mesh_Draw(skysphere_numverts, skysphere_numtriangles, skysphere_element3i); } - R_Mesh_Draw(skysphere_numverts, skysphere_numtriangles, skysphere_element3i); } void R_Sky(void)