X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=r_clip.c;h=ee67e2b2192bb2d8e8054bf43acaa3a8e5073a0c;hb=d9835a6541d8ae9485eb86c1a79ea14f90edcffc;hp=373e1fa3dc624e5c65c50bc9a95068d756089354;hpb=7d0ec7ce187f7333a7ada2884108757a4fec6449;p=xonotic%2Fdarkplaces.git diff --git a/r_clip.c b/r_clip.c index 373e1fa3..ee67e2b2 100644 --- a/r_clip.c +++ b/r_clip.c @@ -40,10 +40,10 @@ clipsurf_t surfstack; clipedge_t edgehead, edgetail; clipedge_t maxedge = {2000000000.0f}; -cvar_t r_clipwidth = {"r_clipwidth", "800"}; -cvar_t r_clipheight = {"r_clipheight", "600"}; -cvar_t r_clipedges = {"r_clipedges", "32768", true}; -cvar_t r_clipsurfaces = {"r_clipsurfaces", "8192", true}; +cvar_t r_clipwidth = {0, "r_clipwidth", "800"}; +cvar_t r_clipheight = {0, "r_clipheight", "600"}; +cvar_t r_clipedges = {CVAR_SAVE, "r_clipedges", "32768"}; +cvar_t r_clipsurfaces = {CVAR_SAVE, "r_clipsurfaces", "8192"}; int clipwidth = 0, clipheight = 0; int maxclipsurfs = 0, maxclipedges = 0; @@ -65,6 +65,8 @@ float r_clip_viewmatrix[3][3], r_clip_viewmulx, r_clip_viewmuly, r_clip_viewcent //float r_clip_nearclipdist, r_clip_nearclipdist2; tinyplane_t r_clip_viewplane[5]; +mempool_t *r_clip_mempool; + void R_Clip_MakeViewMatrix(void) { float pixelaspect, screenaspect, horizontalfieldofview, verticalfieldofview; @@ -100,35 +102,35 @@ void R_Clip_StartFrame(void) { int i; int newwidth, newheight, newmaxedges, newmaxsurfs; - newwidth = bound(80, (int) r_clipwidth.value, vid.width * 2); - newheight = bound(60, (int) r_clipheight.value, vid.height * 2); - newmaxedges = bound(128, (int) r_clipedges.value, 262144); - newmaxsurfs = bound(32, (int) r_clipsurfaces.value, 65536); + newwidth = bound(80, r_clipwidth.integer, vid.realwidth * 2); + newheight = bound(60, r_clipheight.integer, vid.realheight * 2); + newmaxedges = bound(128, r_clipedges.integer, 262144); + newmaxsurfs = bound(32, r_clipsurfaces.integer, 65536); if (newwidth != clipwidth || newheight != clipheight || maxclipedges != newmaxedges || maxclipsurfs != newmaxsurfs) { #if CLIPTEST if (clipbuffer) - qfree(clipbuffer); + Mem_Free(clipbuffer); #endif if (clipedges) - qfree(clipedges); + Mem_Free(clipedges); if (clipsurfs) - qfree(clipsurfs); + Mem_Free(clipsurfs); if (newedges) - qfree(newedges); + Mem_Free(newedges); if (removeedges) - qfree(removeedges); + Mem_Free(removeedges); clipwidth = newwidth; clipheight = newheight; maxclipedges = newmaxedges; maxclipsurfs = newmaxsurfs; #if CLIPTEST - clipbuffer = qmalloc(clipwidth * clipheight * sizeof(clippixel_t)); + clipbuffer = Mem_Alloc(r_clip_mempool, clipwidth * clipheight * sizeof(clippixel_t)); #endif - clipedges = qmalloc(maxclipedges * sizeof(clipedge_t)); - clipsurfs = qmalloc(maxclipsurfs * sizeof(clipsurf_t)); - newedges = qmalloc(clipheight * sizeof(clipedge_t)); - removeedges = qmalloc(clipheight * sizeof(clipedge_t *)); + clipedges = Mem_Alloc(r_clip_mempool, maxclipedges * sizeof(clipedge_t)); + clipsurfs = Mem_Alloc(r_clip_mempool, maxclipsurfs * sizeof(clipsurf_t)); + newedges = Mem_Alloc(r_clip_mempool, clipheight * sizeof(clipedge_t)); + removeedges = Mem_Alloc(r_clip_mempool, clipheight * sizeof(clipedge_t *)); clipedgesend = clipedges + maxclipedges; clipsurfsend = clipsurfs + maxclipsurfs; } @@ -169,26 +171,18 @@ void R_Clip_EndFrame(void) void r_clip_start(void) { + r_clip_mempool = Mem_AllocPool("R_Clip"); } void r_clip_shutdown(void) { + Mem_FreePool(&r_clip_mempool); #if CLIPTEST - if (clipbuffer) - qfree(clipbuffer); clipbuffer = NULL; #endif - if (clipsurfs) - qfree(clipsurfs); clipsurfs = NULL; - if (clipedges) - qfree(clipedges); clipedges = NULL; - if (newedges) - qfree(newedges); newedges = NULL; - if (removeedges) - qfree(removeedges); removeedges = NULL; clipwidth = -1; clipheight = -1; @@ -217,7 +211,7 @@ int R_Clip_TriangleToPlane(vec3_t point1, vec3_t point2, vec3_t point3, tinyplan number = DotProduct(p->normal, p->normal); if (number >= 0.1f) { - *((long *)&y) = 0x5f3759df - ((* (long *) &number) >> 1); + *((int *)&y) = 0x5f3759df - ((* (int *) &number) >> 1); y = y * (1.5f - (number * 0.5f * y * y)); VectorScale(p->normal, y, p->normal); p->dist = DotProduct(point1, p->normal); @@ -254,7 +248,7 @@ int R_Clip_ClipPolygonToPlane(float *in, float *out, int inpoints, int stride, t float *prevpoint, prevdist, dist, dot; // begin with the last point, then enter the loop with the first point as current - prevpoint = (float *) ((byte *)in + stride * (inpoints - 1)); + prevpoint = (float *) ((qbyte *)in + stride * (inpoints - 1)); prevdist = DotProduct(prevpoint, plane->normal) - plane->dist; prevside = prevdist >= 0 ? SIDE_FRONT : SIDE_BACK; i = 0; @@ -265,7 +259,7 @@ int R_Clip_ClipPolygonToPlane(float *in, float *out, int inpoints, int stride, t prevpoint = in; prevdist = dist; prevside = side; - (byte *)in += stride; + (qbyte *)in += stride; begin: dist = DotProduct(in, plane->normal) - plane->dist; @@ -319,12 +313,12 @@ void R_Clip_AddPolygon (vec_t *points, int numverts, int stride, int solid, void { polyplane = &localplane; // calculate the plane for the polygon - if (!R_Clip_TriangleToPlane((float *) points, (float *) ((byte *)points + stride), (float *) ((byte *)points + 2 * stride), polyplane)) + if (!R_Clip_TriangleToPlane((float *) points, (float *) ((qbyte *)points + stride), (float *) ((qbyte *)points + 2 * stride), polyplane)) { for (i = 0;i < numverts;i++) for (j = i + 1;j < numverts;j++) for (k = j + 1;k < numverts;k++) - if (R_Clip_TriangleToPlane((float *) ((byte *)points + i * stride), (float *) ((byte *)points + j * stride), (float *) ((byte *)points + k * stride), polyplane)) + if (R_Clip_TriangleToPlane((float *) ((qbyte *)points + i * stride), (float *) ((qbyte *)points + j * stride), (float *) ((qbyte *)points + k * stride), polyplane)) goto valid1; return; // gave up valid1:; @@ -338,12 +332,12 @@ void R_Clip_AddPolygon (vec_t *points, int numverts, int stride, int solid, void else { // calculate the plane for the polygon - if (!R_Clip_TriangleToPlane((float *) points, (float *) ((byte *)points + stride), (float *) ((byte *)points + 2 * stride), &localplane)) + if (!R_Clip_TriangleToPlane((float *) points, (float *) ((qbyte *)points + stride), (float *) ((qbyte *)points + 2 * stride), &localplane)) { for (i = 0;i < numverts;i++) for (j = i + 1;j < numverts;j++) for (k = j + 1;k < numverts;k++) - if (R_Clip_TriangleToPlane((float *) ((byte *)points + i * stride), (float *) ((byte *)points + j * stride), (float *) ((byte *)points + k * stride), &localplane)) + if (R_Clip_TriangleToPlane((float *) ((qbyte *)points + i * stride), (float *) ((qbyte *)points + j * stride), (float *) ((qbyte *)points + k * stride), &localplane)) goto valid4; return; // gave up valid4:; @@ -877,11 +871,12 @@ void ScanEdges (void) void R_Clip_DisplayBuffer(void) { + /* #if CLIPTEST int i; static int firstupload = true; - byte clipbuffertex[256*256], *b; - if (!r_render.value) + qbyte clipbuffertex[256*256], *b; + if (!r_render.integer) return; if (clipwidth > 256 || clipheight > 256) return; @@ -892,13 +887,13 @@ void R_Clip_DisplayBuffer(void) memset(clipbuffertex, 0, sizeof(clipbuffertex)); glTexImage2D(GL_TEXTURE_2D, 0, 1, 256, 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, clipbuffertex); } - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if (lighthalf) - glColor3f(0.5, 0.5, 0.5); + glColor4ub(0.5, 0.5, 0.5); else - glColor3f(1, 1, 1); + glColor4ub(1, 1, 1); firstupload = false; b = clipbuffertex; for (i = 0;i < clipwidth*clipheight;i++) @@ -910,15 +905,16 @@ void R_Clip_DisplayBuffer(void) } glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, clipwidth, clipheight, GL_LUMINANCE, GL_UNSIGNED_BYTE, clipbuffertex); glBegin (GL_QUADS); - glTexCoord2f (0 , 0 );glVertex2f (0 , 0 ); - glTexCoord2f (clipwidth / 256.0f, 0 );glVertex2f (vid.width, 0 ); - glTexCoord2f (clipwidth / 256.0f, clipheight / 256.0f);glVertex2f (vid.width, vid.height); - glTexCoord2f (0 , clipheight / 256.0f);glVertex2f (0 , vid.height); + glTexCoord2f (0 , 0 );glVertex2f (0 , 0 ); + glTexCoord2f (clipwidth / 256.0f, 0 );glVertex2f (vid.conwidth, 0 ); + glTexCoord2f (clipwidth / 256.0f, clipheight / 256.0f);glVertex2f (vid.conwidth, vid.conheight); + glTexCoord2f (0 , clipheight / 256.0f);glVertex2f (0 , vid.conheight); glEnd (); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); -// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); #endif + */ } float boxpoints[4*3];