-#include "quakedef.h"
-
-void LoadSky_f(void);
-cvar_t r_skyquality = {CVAR_SAVE, "r_skyquality", "2"};
-cvar_t r_skyflush = {0, "r_skyflush", "0"};
-
-static char skyworldname[1024];
-rtexture_t *solidskytexture;
-rtexture_t *alphaskytexture;
-static qboolean skyavailable_quake;
-static qboolean skyavailable_box;
-static rtexturepool_t *skytexturepool;
+#include "quakedef.h"
+#include "image.h"
+// FIXME: fix skybox after vid_restart
+cvar_t r_sky = {CVAR_SAVE, "r_sky", "1"};
+qboolean skyavailable_quake;
+qboolean skyavailable_box;
int skyrendernow;
int skyrendermasked;
-int skyrenderglquake;
-
-static void r_sky_start(void)
-{
- skytexturepool = R_AllocTexturePool();
- solidskytexture = NULL;
- alphaskytexture = NULL;
-}
-
-static void r_sky_shutdown(void)
-{
- R_FreeTexturePool(&skytexturepool);
- solidskytexture = NULL;
- alphaskytexture = NULL;
-}
-
-int R_SetSkyBox(char *sky);
-
-static void r_sky_newmap(void)
-{
- skyavailable_quake = false;
- if (!strcmp(skyworldname, cl.worldmodel->name))
- skyavailable_quake = true;
-}
-
-void R_Sky_Init(void)
-{
- Cmd_AddCommand ("loadsky", &LoadSky_f);
- Cvar_RegisterVariable (&r_skyquality);
- Cvar_RegisterVariable (&r_skyflush);
- R_RegisterModule("R_Sky", r_sky_start, r_sky_shutdown, r_sky_newmap);
-}
+static rtexture_t *solidskytexture;
+static rtexture_t *alphaskytexture;
static int skyrendersphere;
static int skyrenderbox;
+static rtexturepool_t *skytexturepool;
+static char skyname[256];
+static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
+static rtexture_t *skyboxside[6];
void R_SkyStartFrame(void)
{
skyrendernow = false;
skyrendersphere = false;
skyrenderbox = false;
- skyrenderglquake = false;
skyrendermasked = false;
- if (r_skyquality.integer >= 1 && !fogenabled)
+ if (r_sky.integer && !fogenabled)
{
if (skyavailable_box)
skyrenderbox = true;
else if (skyavailable_quake)
- {
- switch(r_skyquality.integer)
- {
- case 1:
- skyrenderglquake = true;
- break;
- default:
- case 2:
- skyrendersphere = true;
- break;
- }
- }
- if (skyrenderbox || skyrendersphere)
- {
- // for depth-masked sky, render the sky on the first sky surface encountered
- skyrendernow = true;
- skyrendermasked = true;
- }
+ skyrendersphere = true;
+ // for depth-masked sky, render the sky on the first sky surface encountered
+ skyrendernow = true;
+ skyrendermasked = true;
}
}
-static char skyname[256];
-
/*
==================
R_SetSkyBox
==================
*/
-static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
-static rtexture_t *skyboxside[6];
-int R_SetSkyBox(char *sky)
+int R_SetSkyBox(const char *sky)
{
int i;
char name[1024];
continue;
}
}
- skyboxside[i] = R_LoadTexture(skytexturepool, va("skyboxside%d", i), image_width, image_height, image_rgba, TEXTYPE_RGBA, TEXF_PRECACHE);
+ skyboxside[i] = R_LoadTexture2D(skytexturepool, va("skyboxside%d", i), image_width, image_height, image_rgba, TEXTYPE_RGBA, TEXF_CLAMP | TEXF_PRECACHE, NULL);
Mem_Free(image_rgba);
}
}
}
-#define R_SkyBoxPolyVec(i,s,t,x,y,z) \
- vert[i][0] = (x) * 1024.0f + r_origin[0];\
- vert[i][1] = (y) * 1024.0f + r_origin[1];\
- vert[i][2] = (z) * 1024.0f + r_origin[2];\
- st[i][0] = (s) * (254.0f/256.0f) + (1.0f/256.0f);\
- st[i][1] = (t) * (254.0f/256.0f) + (1.0f/256.0f);
-
-int skyboxindex[6] = {0, 1, 2, 0, 2, 3};
-
static void R_SkyBox(void)
{
- float vert[4][4], st[4][2];
- rmeshinfo_t m;
+ rmeshstate_t m;
+
+#define R_SkyBoxPolyVec(i,s,t,x,y,z) \
+ varray_vertex[i * 4 + 0] = (x) * 16.0f;\
+ varray_vertex[i * 4 + 1] = (y) * 16.0f;\
+ varray_vertex[i * 4 + 2] = (z) * 16.0f;\
+ varray_texcoord[0][i * 4 + 0] = (s);\
+ varray_texcoord[0][i * 4 + 1] = (t);
+
memset(&m, 0, sizeof(m));
- m.transparent = false;
m.blendfunc1 = GL_ONE;
m.blendfunc2 = GL_ZERO;
- m.numtriangles = 2;
- m.numverts = 4;
- m.index = skyboxindex;
- m.vertex = &vert[0][0];
- m.vertexstep = sizeof(float[4]);
- m.cr = 1;
- m.cg = 1;
- m.cb = 1;
- m.ca = 1;
- m.texcoords[0] = &st[0][0];
- m.texcoordstep[0] = sizeof(float[2]);
+ m.depthdisable = true; // don't modify or read zbuffer
m.tex[0] = R_GetTexture(skyboxside[3]); // front
+ R_Mesh_State(&m);
+
+ GL_Color(r_colorscale, r_colorscale, r_colorscale, 1);
+
R_SkyBoxPolyVec(0, 1, 0, 1, -1, 1);
R_SkyBoxPolyVec(1, 1, 1, 1, -1, -1);
R_SkyBoxPolyVec(2, 0, 1, 1, 1, -1);
R_SkyBoxPolyVec(3, 0, 0, 1, 1, 1);
- R_Mesh_Draw(&m);
+ R_Mesh_Draw(4, 2, polygonelements);
m.tex[0] = R_GetTexture(skyboxside[1]); // back
+ R_Mesh_State(&m);
R_SkyBoxPolyVec(0, 1, 0, -1, 1, 1);
R_SkyBoxPolyVec(1, 1, 1, -1, 1, -1);
R_SkyBoxPolyVec(2, 0, 1, -1, -1, -1);
R_SkyBoxPolyVec(3, 0, 0, -1, -1, 1);
- R_Mesh_Draw(&m);
+ R_Mesh_Draw(4, 2, polygonelements);
m.tex[0] = R_GetTexture(skyboxside[0]); // right
+ R_Mesh_State(&m);
R_SkyBoxPolyVec(0, 1, 0, 1, 1, 1);
R_SkyBoxPolyVec(1, 1, 1, 1, 1, -1);
R_SkyBoxPolyVec(2, 0, 1, -1, 1, -1);
R_SkyBoxPolyVec(3, 0, 0, -1, 1, 1);
- R_Mesh_Draw(&m);
+ R_Mesh_Draw(4, 2, polygonelements);
m.tex[0] = R_GetTexture(skyboxside[2]); // left
+ R_Mesh_State(&m);
R_SkyBoxPolyVec(0, 1, 0, -1, -1, 1);
R_SkyBoxPolyVec(1, 1, 1, -1, -1, -1);
R_SkyBoxPolyVec(2, 0, 1, 1, -1, -1);
R_SkyBoxPolyVec(3, 0, 0, 1, -1, 1);
- R_Mesh_Draw(&m);
+ R_Mesh_Draw(4, 2, polygonelements);
m.tex[0] = R_GetTexture(skyboxside[4]); // up
+ R_Mesh_State(&m);
R_SkyBoxPolyVec(0, 1, 0, 1, -1, 1);
R_SkyBoxPolyVec(1, 1, 1, 1, 1, 1);
R_SkyBoxPolyVec(2, 0, 1, -1, 1, 1);
R_SkyBoxPolyVec(3, 0, 0, -1, -1, 1);
- R_Mesh_Draw(&m);
+ R_Mesh_Draw(4, 2, polygonelements);
m.tex[0] = R_GetTexture(skyboxside[5]); // down
+ R_Mesh_State(&m);
R_SkyBoxPolyVec(0, 1, 0, 1, 1, -1);
R_SkyBoxPolyVec(1, 1, 1, 1, -1, -1);
R_SkyBoxPolyVec(2, 0, 1, -1, -1, -1);
R_SkyBoxPolyVec(3, 0, 0, -1, 1, -1);
- R_Mesh_Draw(&m);
+ R_Mesh_Draw(4, 2, polygonelements);
}
-#define skygridx 16
+#define skygridx 32
#define skygridx1 (skygridx + 1)
#define skygridxrecip (1.0f / (skygridx))
#define skygridy 32
#define skygridy1 (skygridy + 1)
#define skygridyrecip (1.0f / (skygridy))
+#define skysphere_numverts (skygridx1 * skygridy1)
+#define skysphere_numtriangles (skygridx * skygridy * 2)
+static float skysphere_vertex[skysphere_numverts * 4];
+static float skysphere_texcoord[skysphere_numverts * 4];
+static int skysphere_elements[skysphere_numtriangles * 3];
-static float skysphere[skygridx1*skygridy1*5];
-static int skysphereindices[skygridx*skygridy*6];
-static void skyspherecalc(float *sphere, float dx, float dy, float dz)
+static void skyspherecalc(void)
{
- float a, b, x, ax, ay, v[3], length;
- int i, j, *index;
+ int i, j, *e;
+ float a, b, x, ax, ay, v[3], length, *vertex, *texcoord;
+ float dx, dy, dz;
+ dx = 16;
+ dy = 16;
+ dz = 16 / 3;
+ vertex = skysphere_vertex;
+ texcoord = skysphere_texcoord;
for (j = 0;j <= skygridy;j++)
{
a = j * skygridyrecip;
for (i = 0;i <= skygridx;i++)
{
b = i * skygridxrecip;
- x = cos(b * M_PI * 2);
+ x = cos((b + 0.5) * M_PI);
v[0] = ax*x * dx;
v[1] = ay*x * dy;
- v[2] = -sin(b * M_PI * 2) * dz;
+ v[2] = -sin((b + 0.5) * M_PI) * dz;
length = 3.0f / sqrt(v[0]*v[0]+v[1]*v[1]+(v[2]*v[2]*9));
- *sphere++ = v[0] * length;
- *sphere++ = v[1] * length;
- *sphere++ = v[0];
- *sphere++ = v[1];
- *sphere++ = v[2];
+ *texcoord++ = v[0] * length;
+ *texcoord++ = v[1] * length;
+ *texcoord++ = 0;
+ *texcoord++ = 0;
+ *vertex++ = v[0];
+ *vertex++ = v[1];
+ *vertex++ = v[2];
+ *vertex++ = 1;
}
}
- index = skysphereindices;
+ e = skysphere_elements;
for (j = 0;j < skygridy;j++)
{
for (i = 0;i < skygridx;i++)
{
- *index++ = j * skygridx1 + i;
- *index++ = j * skygridx1 + i + 1;
- *index++ = (j + 1) * skygridx1 + i;
+ *e++ = j * skygridx1 + i;
+ *e++ = j * skygridx1 + i + 1;
+ *e++ = (j + 1) * skygridx1 + i;
- *index++ = j * skygridx1 + i + 1;
- *index++ = (j + 1) * skygridx1 + i + 1;
- *index++ = (j + 1) * skygridx1 + i;
+ *e++ = j * skygridx1 + i + 1;
+ *e++ = (j + 1) * skygridx1 + i + 1;
+ *e++ = (j + 1) * skygridx1 + i;
}
i++;
}
}
-static void skyspherearrays(float *vert, float *tex, float *tex2, float *source, float s, float s2)
-{
- float *v, *t, *t2, radius;
- int i;
- v = vert;
- t = tex;
- t2 = tex2;
- radius = r_farclip - 8;
- for (i = 0;i < (skygridx1*skygridy1);i++)
- {
- *t++ = source[0] + s;
- *t++ = source[1] + s;
- *t2++ = source[0] + s2;
- *t2++ = source[1] + s2;
- *v++ = source[2] + r_origin[0];
- *v++ = source[3] + r_origin[1];
- *v++ = source[4] + r_origin[2];
- *v++ = 0;
- source += 5;
- }
-}
-
static void R_SkySphere(void)
{
- float speedscale, speedscale2;
- float vert[skygridx1*skygridy1*4], tex[skygridx1*skygridy1*2], tex2[skygridx1*skygridy1*2];
+ int i;
+ float speedscale, *t;
static qboolean skysphereinitialized = false;
- rmeshinfo_t m;
+ rmeshstate_t m;
if (!skysphereinitialized)
{
skysphereinitialized = true;
- skyspherecalc(skysphere, 1024, 1024, 1024 / 3);
+ skyspherecalc();
}
+
+ // scroll speed for upper layer
+ speedscale = cl.time*8.0/128.0;
+ // wrap the scroll just to be extra kind to float accuracy
+ speedscale -= (int)speedscale;
+
+ R_Mesh_ResizeCheck(skysphere_numverts);
+
memset(&m, 0, sizeof(m));
- m.transparent = false;
m.blendfunc1 = GL_ONE;
m.blendfunc2 = GL_ZERO;
- m.numtriangles = skygridx*skygridy*2;
- m.numverts = skygridx1*skygridy1;
- m.index = skysphereindices;
- m.vertex = vert;
- m.vertexstep = sizeof(float[4]);
- m.cr = 1;
- m.cg = 1;
- m.cb = 1;
- m.ca = 1;
- m.texcoords[0] = tex;
- m.texcoordstep[0] = sizeof(float[2]);
- speedscale = cl.time*8.0/128.0;
- speedscale -= (int)speedscale;
- speedscale2 = cl.time*16.0/128.0;
- speedscale2 -= (int)speedscale2;
- skyspherearrays(vert, tex, tex2, skysphere, speedscale, speedscale2);
+ m.depthdisable = true; // don't modify or read zbuffer
m.tex[0] = R_GetTexture(solidskytexture);
- R_Mesh_Draw(&m);
+ R_Mesh_State(&m);
+
+ GL_Color(r_colorscale, r_colorscale, r_colorscale, 1);
+
+ memcpy(varray_vertex, skysphere_vertex, skysphere_numverts * sizeof(float[4]));
+ memcpy(varray_texcoord[0], skysphere_texcoord, skysphere_numverts * sizeof(float[4]));
+ for (i = 0, t = varray_texcoord[0];i < skysphere_numverts;i++, t += 4)
+ {
+ t[0] += speedscale;
+ t[1] += speedscale;
+ }
+ R_Mesh_Draw(skysphere_numverts, skysphere_numtriangles, skysphere_elements);
m.blendfunc1 = GL_SRC_ALPHA;
m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
m.tex[0] = R_GetTexture(alphaskytexture);
- m.texcoords[0] = tex2;
- R_Mesh_Draw(&m);
+ R_Mesh_State(&m);
+
+ // scroll it again, this makes the lower cloud layer scroll twice as fast (just like quake did)
+ for (i = 0, t = varray_texcoord[0];i < skysphere_numverts;i++, t += 4)
+ {
+ t[0] += speedscale;
+ t[1] += speedscale;
+ }
+ R_Mesh_Draw(skysphere_numverts, skysphere_numtriangles, skysphere_elements);
}
void R_Sky(void)
{
+ matrix4x4_t skymatrix;
if (skyrendermasked)
{
+ Matrix4x4_CreateTranslate(&skymatrix, r_origin[0], r_origin[1], r_origin[2]);
+ R_Mesh_Matrix(&skymatrix);
if (skyrendersphere)
+ {
+ // this does not modify depth buffer
R_SkySphere();
+ }
else if (skyrenderbox)
+ {
+ // this does not modify depth buffer
R_SkyBox();
-
- // clear the zbuffer that was used while rendering the sky
- R_Mesh_ClearDepth();
+ }
+ /* this will be skyroom someday
+ else
+ {
+ // this modifies the depth buffer so we have to clear it afterward
+ //R_SkyRoom();
+ // clear the depthbuffer that was used while rendering the skyroom
+ //qglClear(GL_DEPTH_BUFFER_BIT);
+ }
+ */
}
}
qbyte skyupperlayerpixels[128*128*4], skylowerlayerpixels[128*128*4];
unsigned trans[128*128], transpix, *rgba;
- strcpy(skyworldname, loadmodel->name);
+ skyavailable_quake = true;
// flush skytexturepool so we won't build up a leak from uploading textures multiple times
R_FreeTexturePool(&skytexturepool);
{
for (i = 0;i < 128;i++)
for (j = 0;j < 128;j++)
- trans[(i*128) + j] = src[i*256+j+128];
+ trans[(i*128) + j] = ((unsigned *)src)[i*256+j+128];
}
else
{
for (j=0 ; j<128 ; j++)
{
p = src[i*256 + j + 128];
- rgba = &d_8to24table[p];
+ rgba = &palette_complete[p];
trans[(i*128) + j] = *rgba;
r += ((qbyte *)rgba)[0];
g += ((qbyte *)rgba)[1];
memcpy(skyupperlayerpixels, trans, 128*128*4);
- solidskytexture = R_LoadTexture (skytexturepool, "sky_solidtexture", 128, 128, (qbyte *) trans, TEXTYPE_RGBA, TEXF_PRECACHE);
- /*
- for (i = 0;i < 128*128;i++)
- {
- ((qbyte *)&trans[i])[0] >>= 1;
- ((qbyte *)&trans[i])[1] >>= 1;
- ((qbyte *)&trans[i])[2] >>= 1;
- }
- solidskytexture_half = R_LoadTexture (skytexturepool, "sky_solidtexture_half", 128, 128, (qbyte *) trans, TEXTYPE_RGBA, TEXF_PRECACHE);
- */
+ solidskytexture = R_LoadTexture2D(skytexturepool, "sky_solidtexture", 128, 128, (qbyte *) trans, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
if (bytesperpixel == 4)
{
for (i = 0;i < 128;i++)
for (j = 0;j < 128;j++)
- trans[(i*128) + j] = src[i*256+j];
+ trans[(i*128) + j] = ((unsigned *)src)[i*256+j];
}
else
{
if (p == 0)
trans[(i*128) + j] = transpix;
else
- trans[(i*128) + j] = d_8to24table[p];
+ trans[(i*128) + j] = palette_complete[p];
}
}
}
memcpy(skylowerlayerpixels, trans, 128*128*4);
- alphaskytexture = R_LoadTexture (skytexturepool, "sky_alphatexture", 128, 128, (qbyte *) trans, TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE);
- /*
- for (i = 0;i < 128*128;i++)
- {
- ((qbyte *)&trans[i])[0] >>= 1;
- ((qbyte *)&trans[i])[1] >>= 1;
- ((qbyte *)&trans[i])[2] >>= 1;
- }
- alphaskytexture_half = R_LoadTexture (skytexturepool, "sky_alphatexture_half", 128, 128, (qbyte *) trans, TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE);
- */
+ alphaskytexture = R_LoadTexture2D(skytexturepool, "sky_alphatexture", 128, 128, (qbyte *) trans, TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE, NULL);
+}
+
+void R_ResetQuakeSky(void)
+{
+ skyavailable_quake = false;
+}
+
+void R_ResetSkyBox(void)
+{
+ skyboxside[0] = skyboxside[1] = skyboxside[2] = skyboxside[3] = skyboxside[4] = skyboxside[5] = NULL;
+ skyname[0] = 0;
+ skyavailable_box = false;
+}
+
+static void r_sky_start(void)
+{
+ skytexturepool = R_AllocTexturePool();
+ solidskytexture = NULL;
+ alphaskytexture = NULL;
+}
+
+static void r_sky_shutdown(void)
+{
+ R_FreeTexturePool(&skytexturepool);
+ solidskytexture = NULL;
+ alphaskytexture = NULL;
+}
+
+static void r_sky_newmap(void)
+{
+}
+
+void R_Sky_Init(void)
+{
+ Cmd_AddCommand ("loadsky", &LoadSky_f);
+ Cvar_RegisterVariable (&r_sky);
+ R_RegisterModule("R_Sky", r_sky_start, r_sky_shutdown, r_sky_newmap);
}