X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=r_clip.c;h=8625a2a1486def2298b8aaad78024cb228f5726e;hb=e3c47ecd0908e10adfa0f39597813a0163d26705;hp=1f59dc320185e3cd06832d8f70ba13f700e626e8;hpb=8468ffaf8162a4fe8361127385c40141c375661d;p=xonotic%2Fdarkplaces.git diff --git a/r_clip.c b/r_clip.c index 1f59dc32..8625a2a1 100644 --- a/r_clip.c +++ b/r_clip.c @@ -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; @@ -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:; @@ -880,8 +874,8 @@ 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; @@ -910,10 +904,10 @@ 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);