From 5477352e938285424dff4324a2e4a6314c96087b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 9 Mar 2022 20:19:14 +0900 Subject: [PATCH] [renderer] Abandon sw32 altogether I'd been considering it for a while, but in the end, all the issues it presented made me decide it wasn't worth merging and was never really worth keeping: it was a neat proof of concept but of little actual use, especially now everyone either has an OK GPU or would want to stick to 8-bit rendering anyway (sorry L-Havoc). However, both it and my merge work are preserved in git history :) --- include/context_x11.h | 2 +- include/r_internal.h | 3 - include/r_local.h | 2 +- include/vid_internal.h | 2 - include/vid_sw.h | 29 - include/vid_sw_draw.h | 25 - libs/video/renderer/sw/d_draw.S | 4 +- libs/video/renderer/sw/d_edge.c | 52 +- libs/video/renderer/sw/d_init.c | 15 +- libs/video/renderer/sw/d_modech.c | 5 +- libs/video/renderer/sw/d_part.c | 261 +------- libs/video/renderer/sw/d_parta.S | 4 +- libs/video/renderer/sw/d_polysa.S | 4 +- libs/video/renderer/sw/d_polyse.c | 202 +----- libs/video/renderer/sw/d_scan.c | 423 +----------- libs/video/renderer/sw/d_scana.S | 4 +- libs/video/renderer/sw/d_sky.c | 141 +--- libs/video/renderer/sw/d_spr8.S | 4 +- libs/video/renderer/sw/d_sprite.c | 307 +-------- libs/video/renderer/sw/d_surf.c | 12 +- libs/video/renderer/sw/d_zpoint.c | 36 +- libs/video/renderer/sw/draw.c | 871 ++++++------------------- libs/video/renderer/sw/screen.c | 21 +- libs/video/renderer/sw/surf8.S | 40 +- libs/video/renderer/sw/sw_graph.c | 86 +-- libs/video/renderer/sw/sw_ralias.c | 13 - libs/video/renderer/sw/sw_rmain.c | 28 +- libs/video/renderer/sw/sw_rpart.c | 4 +- libs/video/renderer/sw/sw_rsky.c | 182 +++--- libs/video/renderer/sw/sw_rsurf.c | 613 +++-------------- libs/video/renderer/sw/vid_common_sw.c | 129 +--- libs/video/targets/vid_win_sw.c | 19 - libs/video/targets/vid_x11_sw.c | 20 +- 33 files changed, 471 insertions(+), 3092 deletions(-) delete mode 100644 include/vid_sw_draw.h diff --git a/include/context_x11.h b/include/context_x11.h index 1409b5b93..ebb4b6d3b 100644 --- a/include/context_x11.h +++ b/include/context_x11.h @@ -83,7 +83,7 @@ struct gl_ctx_s *X11_GL_Context (void); void X11_GL_Init_Cvars (void); struct sw_ctx_s *X11_SW_Context (void); -void X11_SW_Init_Cvars (void); // sw and sw32 cvars shared +void X11_SW_Init_Cvars (void); struct vulkan_ctx_s *X11_Vulkan_Context (void); void X11_Vulkan_Init_Cvars (void); diff --git a/include/r_internal.h b/include/r_internal.h index 690aa8629..8a1ae465c 100644 --- a/include/r_internal.h +++ b/include/r_internal.h @@ -14,7 +14,6 @@ extern vid_render_data_t vid_render_data; extern vid_render_funcs_t gl_vid_render_funcs; extern vid_render_funcs_t glsl_vid_render_funcs; extern vid_render_funcs_t sw_vid_render_funcs; -extern vid_render_funcs_t sw32_vid_render_funcs; extern vid_render_funcs_t vulkan_vid_render_funcs; extern vid_render_funcs_t *vid_render_funcs; @@ -30,7 +29,6 @@ void R_LineGraph (int x, int y, int *h_vals, int count, int height); void gl_R_Init (void); void glsl_R_Init (void); void sw_R_Init (void); -void sw32_R_Init (void); void R_RenderFrame (SCR_Func *scr_funcs); void R_Init_Cvars (void); void R_InitEfrags (void); @@ -45,7 +43,6 @@ extern struct psystem_s r_psystem; struct psystem_s *gl_ParticleSystem (void); struct psystem_s *glsl_ParticleSystem (void); struct psystem_s *sw_ParticleSystem (void); -struct psystem_s *sw32_ParticleSystem (void); void R_RunParticles (float dT); void R_NewMap (model_t *worldmodel, model_t **models, int num_models); diff --git a/include/r_local.h b/include/r_local.h index d6d7b35a9..95302ad49 100644 --- a/include/r_local.h +++ b/include/r_local.h @@ -236,7 +236,7 @@ extern float leftclip, topclip, rightclip, bottomclip; extern int r_acliptype; extern finalvert_t *pfinalverts; extern auxvert_t *pauxverts; -extern float ziscale, sw32_ziscale; +extern float ziscale; extern float aliastransform[3][4]; qboolean R_AliasCheckBBox (void); diff --git a/include/vid_internal.h b/include/vid_internal.h index cc574c373..7912dca52 100644 --- a/include/vid_internal.h +++ b/include/vid_internal.h @@ -27,8 +27,6 @@ extern struct cvar_s *vid_gamma; void VID_GetWindowSize (int def_w, int def_h); -extern unsigned short d_8to16table[256]; - void VID_InitGamma (const byte *); qboolean VID_SetGamma (double); void VID_UpdateGamma (struct cvar_s *); diff --git a/include/vid_sw.h b/include/vid_sw.h index 00a15357b..92fb00d55 100644 --- a/include/vid_sw.h +++ b/include/vid_sw.h @@ -1,22 +1,6 @@ #ifndef __vid_sw_h #define __vid_sw_h -#include "QF/qtypes.h" - -struct surf_s; -struct vrect_s; -struct particle_s; -struct spanpackage_s; -struct qpic_s; -struct espan_s; -struct sspan_s; - -typedef struct sw_draw_s { -#define SW_DRAW_FUNC(name, rettype, params) \ - rettype (*name) params; -#include "vid_sw_draw.h" -} sw_draw_t; - struct vrect_s; typedef struct sw_ctx_s { int pixbytes; @@ -24,23 +8,10 @@ typedef struct sw_ctx_s { void (*create_context) (struct sw_ctx_s *ctx); void (*set_palette) (struct sw_ctx_s *ctx, const byte *palette); void (*update) (struct sw_ctx_s *ctx, struct vrect_s *rects); - sw_draw_t *draw; } sw_ctx_t; extern sw_ctx_t *sw_ctx; -#define SW_DRAW_FUNC(name, rettype, params) \ - rettype name##_8 params; -#include "vid_sw_draw.h" - -#define SW_DRAW_FUNC(name, rettype, params) \ - rettype name##_16 params; -#include "vid_sw_draw.h" - -#define SW_DRAW_FUNC(name, rettype, params) \ - rettype name##_32 params; -#include "vid_sw_draw.h" - struct tex_s *sw_SCR_CaptureBGR (void); #endif//__vid_sw_h diff --git a/include/vid_sw_draw.h b/include/vid_sw_draw.h deleted file mode 100644 index 879c1cd65..000000000 --- a/include/vid_sw_draw.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SW_DRAW_FUNC -#define SW_DRAW_FUNC(name, rettype, params) -#endif - -SW_DRAW_FUNC(draw_solid_usrface, void, (struct surf_s *surf, int color)) -SW_DRAW_FUNC(draw_particle, void, (struct particle_s *particle)) -SW_DRAW_FUNC(polyset_draw_spans, void, (struct spanpackage_s *spanpackage)) -SW_DRAW_FUNC(draw_character, void, (int x, int y, byte *source, int drawline)) -SW_DRAW_FUNC(draw_pixel, void, (int x, int y, byte color)) -SW_DRAW_FUNC(draw_subpic, void, (int x, int y, struct qpic_s *pic, int srcx, int srcy, int width, int height)) -SW_DRAW_FUNC(draw_console_background, void, (int lines, byte *data)) -SW_DRAW_FUNC(draw_rect, void, (struct vrect_s *rect, int rowbytes, byte *src, int transparent)) -SW_DRAW_FUNC(draw_fill, void, (int x, int y, int w, int h, int c)) -SW_DRAW_FUNC(draw_fadescreen, void, (void)) -SW_DRAW_FUNC(draw_blendscreen, void, (quat_t color)) -SW_DRAW_FUNC(warp_screen, void, (void)) -SW_DRAW_FUNC(draw_turbulent_span, void, (void)) -SW_DRAW_FUNC(draw_spans, void, (struct espan_s *span)) -SW_DRAW_FUNC(draw_sky_scans, void, (struct espan_s *span)) -SW_DRAW_FUNC(sprite_draw_spans, void, (struct sspan_s *span)) -SW_DRAW_FUNC(draw_z_point, void, (void)) -SW_DRAW_FUNC(line_grapn, void, (int x, int y, int *h_vals, int count, int height)) -SW_DRAW_FUNC(make_sky, void, (void)) -SW_DRAW_FUNC(capture_bgr, struct tex_s *, (void)) -#undef SW_DRAW_FUNC diff --git a/libs/video/renderer/sw/d_draw.S b/libs/video/renderer/sw/d_draw.S index e615d677f..e4642025b 100644 --- a/libs/video/renderer/sw/d_draw.S +++ b/libs/video/renderer/sw/d_draw.S @@ -99,8 +99,8 @@ LClampHigh5: #define pspans 4+16 .align 4 -.globl C(draw_spans_8) -C(draw_spans_8): +.globl C(D_DrawSpans8) +C(D_DrawSpans8): pushl %ebp // preserve caller's stack frame pushl %edi pushl %esi // preserve register variables diff --git a/libs/video/renderer/sw/d_edge.c b/libs/video/renderer/sw/d_edge.c index 9b50e932b..59963dc3a 100644 --- a/libs/video/renderer/sw/d_edge.c +++ b/libs/video/renderer/sw/d_edge.c @@ -35,8 +35,6 @@ #include "d_local.h" #include "r_internal.h" -#include "vid_internal.h" -#include "vid_sw.h" static int miplevel; @@ -74,14 +72,15 @@ D_MipLevelForScale (float scale) // FIXME: clean this up -void -draw_solid_usrface_8 (surf_t *surf, int color) +static void +D_DrawSolidSurface (surf_t *surf, int color) { + espan_t *span; byte *pdest; int u, u2, pix; pix = (color << 24) | (color << 16) | (color << 8) | color; - for (espan_t *span = surf->spans; span; span = span->pnext) { + for (span = surf->spans; span; span = span->pnext) { pdest = (byte *) d_viewbuffer + screenwidth * span->v; u = span->u; u2 = span->u + span->count - 1; @@ -104,39 +103,6 @@ draw_solid_usrface_8 (surf_t *surf, int color) } } -void -draw_solid_usrface_16 (surf_t *surf, int color) -{ - short *pdest, pix; - int u, u2; - - pix = d_8to16table[color]; - for (espan_t *span = surf->spans; span; span = span->pnext) { - pdest = (short *) d_viewbuffer + screenwidth * span->v; - u = span->u; - u2 = span->u + span->count - 1; - for (;u <= u2; u++) { - pdest[u] = pix; - } - } -} - -void -draw_solid_usrface_32 (surf_t *surf, int color) -{ - int *pdest, pix; - int u, u2; - - pix = d_8to24table[color]; - for (espan_t *span = surf->spans; span; span = span->pnext) { - pdest = (int *) d_viewbuffer + screenwidth * span->v; - u = span->u; - u2 = span->u + span->count - 1; - for (;u <= u2; u++) { - pdest[u] = pix; - } - } -} static void D_CalcGradients (msurface_t *pface) @@ -201,8 +167,7 @@ D_DrawSurfaces (void) d_zistepv = s->d_zistepv; d_ziorigin = s->d_ziorigin; - int color = (size_t) s->data & 0xff; - sw_ctx->draw->draw_solid_usrface (s, color); + D_DrawSolidSurface (s, ((size_t) s->data & 0xFF)); D_DrawZSpans (s->spans); } } else { @@ -218,10 +183,10 @@ D_DrawSurfaces (void) if (s->flags & SURF_DRAWSKY) { if (!r_skymade) { - sw_ctx->draw->make_sky (); + R_MakeSky (); } - sw_ctx->draw->draw_sky_scans (s->spans); + D_DrawSkyScans (s->spans); D_DrawZSpans (s->spans); } else if (s->flags & SURF_DRAWBACKGROUND) { // set up a gradient for the background surface that places @@ -230,8 +195,7 @@ D_DrawSurfaces (void) d_zistepv = 0; d_ziorigin = -0.9; - int color = r_clearcolor->int_val & 0xff; - sw_ctx->draw->draw_solid_usrface (s, color); + D_DrawSolidSurface (s, r_clearcolor->int_val & 0xFF); D_DrawZSpans (s->spans); } else if (s->flags & SURF_DRAWTURB) { pface = s->data; diff --git a/libs/video/renderer/sw/d_init.c b/libs/video/renderer/sw/d_init.c index bfd7de7f6..634762d28 100644 --- a/libs/video/renderer/sw/d_init.c +++ b/libs/video/renderer/sw/d_init.c @@ -35,7 +35,6 @@ #include "d_local.h" #include "r_internal.h" #include "vid_internal.h" -#include "vid_sw.h" #define NUM_MIPS 4 @@ -46,7 +45,6 @@ float d_scalemip[NUM_MIPS - 1]; static float basemip[NUM_MIPS - 1] = { 1.0, 0.5 * 0.8, 0.25 * 0.8 }; -float d_zitable[65536]; void (*d_drawspans) (espan_t *pspan); @@ -62,16 +60,7 @@ D_Init (void) vr_data.vid->vid_internal->flush_caches = D_FlushCaches; vr_data.vid->vid_internal->init_caches = D_InitCaches; - // LordHavoc: compute 1/zi table for use in rendering code everywhere - if (!d_zitable[1]) { - int i; - d_zitable[0] = 0; - for (i = 1;i < 65536;i++) - d_zitable[i] = (65536.0 * 65536.0 / (double) i); - } - VID_InitBuffers (); - VID_MakeColormaps (); } void @@ -93,7 +82,7 @@ D_SetupFrame (void) if (r_dowarp) screenwidth = WARP_WIDTH; else - screenwidth = vid.rowbytes / sw_ctx->pixbytes; + screenwidth = vid.rowbytes; d_roverwrapped = false; d_initial_rover = sc_rover; @@ -103,7 +92,7 @@ D_SetupFrame (void) for (i = 0; i < (NUM_MIPS - 1); i++) d_scalemip[i] = basemip[i] * d_mipscale->value; - d_drawspans = sw_ctx->draw->draw_spans; + d_drawspans = D_DrawSpans8; } void diff --git a/libs/video/renderer/sw/d_modech.c b/libs/video/renderer/sw/d_modech.c index c0ab33618..40956fc53 100644 --- a/libs/video/renderer/sw/d_modech.c +++ b/libs/video/renderer/sw/d_modech.c @@ -31,9 +31,8 @@ #include "QF/render.h" #include "QF/sys.h" -#include "d_local.h" #include "r_internal.h" -#include "vid_sw.h" +#include "d_local.h" int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle; @@ -71,7 +70,7 @@ D_ViewChanged (void) if (r_dowarp) rowpixels = WARP_WIDTH; else - rowpixels = vid.rowbytes / sw_ctx->pixbytes; + rowpixels = vid.rowbytes; scale_for_mip = xscale; if (yscale > xscale) diff --git a/libs/video/renderer/sw/d_part.c b/libs/video/renderer/sw/d_part.c index 7052462e8..b8b5b1c82 100644 --- a/libs/video/renderer/sw/d_part.c +++ b/libs/video/renderer/sw/d_part.c @@ -30,8 +30,6 @@ #include "d_local.h" #include "r_internal.h" -#include "vid_internal.h" -#include "vid_sw.h" #ifdef PIC @@ -40,7 +38,7 @@ #ifndef USE_INTEL_ASM void -draw_particle_8 (particle_t *pparticle) +D_DrawParticle (particle_t *pparticle) { vec3_t local, transformed; float zi; @@ -165,260 +163,3 @@ draw_particle_8 (particle_t *pparticle) } } #endif // !USE_INTEL_ASM - -void -draw_particle_16 (particle_t *pparticle) -{ - vec3_t local, transformed; - float zi; - short *pz; - int i, izi, pix, count, u, v; - - // transform point - VectorSubtract (pparticle->pos, r_origin, local); - - transformed[0] = DotProduct (local, r_pright); - transformed[1] = DotProduct (local, r_pup); - transformed[2] = DotProduct (local, r_ppn); - - if (transformed[2] < PARTICLE_Z_CLIP) - return; - - // project the point - // FIXME: preadjust xcenter and ycenter - zi = 1.0 / transformed[2]; - u = (int) (xcenter + zi * transformed[0] + 0.5); - v = (int) (ycenter - zi * transformed[1] + 0.5); - - if ((v > d_vrectbottom_particle) - || (u > d_vrectright_particle) - || (v < d_vrecty) || (u < d_vrectx)) { - return; - } - - pz = d_pzbuffer + (d_zwidth * v) + u; - izi = (int) (zi * 0x8000); - - pix = izi >> d_pix_shift; - - if (pix < d_pix_min) - pix = d_pix_min; - else if (pix > d_pix_max) - pix = d_pix_max; - - unsigned short *pdest = (unsigned short *) d_viewbuffer + - d_scantable[v] + u, - pixcolor = d_8to16table[(int) pparticle->icolor]; - switch (pix) { - case 1: - count = 1 << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - if (pz[0] <= izi) { - pz[0] = izi; - pdest[0] = pixcolor; - } - } - break; - case 2: - count = 2 << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - if (pz[0] <= izi) { - pz[0] = izi; - pdest[0] = pixcolor; - } - - if (pz[1] <= izi) { - pz[1] = izi; - pdest[1] = pixcolor; - } - } - break; - case 3: - count = 3 << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - if (pz[0] <= izi) { - pz[0] = izi; - pdest[0] = pixcolor; - } - - if (pz[1] <= izi) { - pz[1] = izi; - pdest[1] = pixcolor; - } - - if (pz[2] <= izi) { - pz[2] = izi; - pdest[2] = pixcolor; - } - } - break; - case 4: - count = 4 << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - if (pz[0] <= izi) { - pz[0] = izi; - pdest[0] = pixcolor; - } - - if (pz[1] <= izi) { - pz[1] = izi; - pdest[1] = pixcolor; - } - - if (pz[2] <= izi) { - pz[2] = izi; - pdest[2] = pixcolor; - } - - if (pz[3] <= izi) { - pz[3] = izi; - pdest[3] = pixcolor; - } - } - break; - default: - count = pix << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - for (i = 0; i < pix; i++) { - if (pz[i] <= izi) { - pz[i] = izi; - pdest[i] = pixcolor; - } - } - } - break; - } -} - -void -draw_particle_32 (particle_t *pparticle) -{ - vec3_t local, transformed; - float zi; - short *pz; - int i, izi, pix, count, u, v; - - // transform point - VectorSubtract (pparticle->pos, r_origin, local); - - transformed[0] = DotProduct (local, r_pright); - transformed[1] = DotProduct (local, r_pup); - transformed[2] = DotProduct (local, r_ppn); - - if (transformed[2] < PARTICLE_Z_CLIP) - return; - - // project the point - // FIXME: preadjust xcenter and ycenter - zi = 1.0 / transformed[2]; - u = (int) (xcenter + zi * transformed[0] + 0.5); - v = (int) (ycenter - zi * transformed[1] + 0.5); - - if ((v > d_vrectbottom_particle) - || (u > d_vrectright_particle) - || (v < d_vrecty) || (u < d_vrectx)) { - return; - } - - pz = d_pzbuffer + (d_zwidth * v) + u; - izi = (int) (zi * 0x8000); - - pix = izi >> d_pix_shift; - - if (pix < d_pix_min) - pix = d_pix_min; - else if (pix > d_pix_max) - pix = d_pix_max; - - int *pdest = (int *) d_viewbuffer + d_scantable[v] + u, - pixcolor = d_8to24table[(int) pparticle->icolor]; - switch (pix) { - case 1: - count = 1 << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - if (pz[0] <= izi) { - pz[0] = izi; - pdest[0] = pixcolor; - } - } - break; - case 2: - count = 2 << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - if (pz[0] <= izi) { - pz[0] = izi; - pdest[0] = pixcolor; - } - - if (pz[1] <= izi) { - pz[1] = izi; - pdest[1] = pixcolor; - } - } - break; - case 3: - count = 3 << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - if (pz[0] <= izi) { - pz[0] = izi; - pdest[0] = pixcolor; - } - - if (pz[1] <= izi) { - pz[1] = izi; - pdest[1] = pixcolor; - } - - if (pz[2] <= izi) { - pz[2] = izi; - pdest[2] = pixcolor; - } - } - break; - case 4: - count = 4 << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - if (pz[0] <= izi) { - pz[0] = izi; - pdest[0] = pixcolor; - } - - if (pz[1] <= izi) { - pz[1] = izi; - pdest[1] = pixcolor; - } - - if (pz[2] <= izi) { - pz[2] = izi; - pdest[2] = pixcolor; - } - - if (pz[3] <= izi) { - pz[3] = izi; - pdest[3] = pixcolor; - } - } - break; - default: - count = pix << d_y_aspect_shift; - - for (; count; count--, pz += d_zwidth, pdest += screenwidth) { - for (i = 0; i < pix; i++) { - if (pz[i] <= izi) { - pz[i] = izi; - pdest[i] = pixcolor; - } - } - } - break; - } -} diff --git a/libs/video/renderer/sw/d_parta.S b/libs/video/renderer/sw/d_parta.S index 13a7a5299..a7b9a8543 100644 --- a/libs/video/renderer/sw/d_parta.S +++ b/libs/video/renderer/sw/d_parta.S @@ -55,8 +55,8 @@ #define P 12+4 .align 4 -.globl C(draw_particle_8) -C(draw_particle_8): +.globl C(D_DrawParticle) +C(D_DrawParticle): pushl %ebp // preserve caller's stack frame pushl %edi // preserve register variables pushl %ebx diff --git a/libs/video/renderer/sw/d_polysa.S b/libs/video/renderer/sw/d_polysa.S index 0c254cbf5..ec2511e30 100644 --- a/libs/video/renderer/sw/d_polysa.S +++ b/libs/video/renderer/sw/d_polysa.S @@ -756,8 +756,8 @@ LDone: .globl C(D_PolysetAff8Start) C(D_PolysetAff8Start): -.globl C(polyset_draw_spans_8) -C(polyset_draw_spans_8): +.globl C(D_PolysetDrawSpans8) +C(D_PolysetDrawSpans8): pushl %esi // preserve register variables pushl %ebx diff --git a/libs/video/renderer/sw/d_polyse.c b/libs/video/renderer/sw/d_polyse.c index a707d807c..5e7f9fbc9 100644 --- a/libs/video/renderer/sw/d_polyse.c +++ b/libs/video/renderer/sw/d_polyse.c @@ -33,7 +33,6 @@ #include "d_local.h" #include "r_internal.h" -#include "vid_sw.h" int ubasestep, errorterm, erroradjustup, erroradjustdown; @@ -43,7 +42,7 @@ int ubasestep, errorterm, erroradjustup, erroradjustdown; // !!! if this is changed, it must be changed in asm_draw.h too !!! typedef struct spanpackage_s { - int pdest; + void *pdest; short *pz; int count; byte *ptex; @@ -94,8 +93,7 @@ int d_aspancount, d_countextrastep; spanpackage_t *a_spans; spanpackage_t *d_pedgespanpackage; static int ystart; -int d_pdest; -byte *d_ptex; +byte *d_pdest, *d_ptex; short *d_pz; int d_sfrac, d_tfrac, d_light, d_zi; int d_ptexextrastep, d_sfracextrastep; @@ -596,7 +594,7 @@ InitGel (byte * palette) #ifndef USE_INTEL_ASM void -polyset_draw_spans_8 (spanpackage_t * pspanpackage) +D_PolysetDrawSpans8 (spanpackage_t * pspanpackage) { int lcount; byte *lpdest; @@ -618,7 +616,7 @@ polyset_draw_spans_8 (spanpackage_t * pspanpackage) } if (lcount) { - lpdest = d_viewbuffer + pspanpackage->pdest; + lpdest = pspanpackage->pdest; lptex = pspanpackage->ptex; lpz = pspanpackage->pz; lsfrac = pspanpackage->sfrac; @@ -653,178 +651,6 @@ polyset_draw_spans_8 (spanpackage_t * pspanpackage) } #endif // !USE_INTEL_ASM -void -polyset_draw_spans_16 (spanpackage_t * pspanpackage) -{ - int i, j, texscantable[2*MAX_LBM_HEIGHT], *texscan; - // LordHavoc: compute skin row table - for (i = 0, j = -r_affinetridesc.skinheight * r_affinetridesc.skinwidth; - i < r_affinetridesc.skinheight*2;i++, j += r_affinetridesc.skinwidth) - texscantable[i] = j; - texscan = texscantable + r_affinetridesc.skinheight; - - { - int lcount, count = 0; - short *lpdest; - byte *lptex; - int lsfrac, ltfrac; - int llight; - int lzi; - short *lpz; - - do - { - lcount = d_aspancount - pspanpackage->count; - - errorterm += erroradjustup; - if (errorterm >= 0) - { - d_aspancount += d_countextrastep; - errorterm -= erroradjustdown; - } - else - d_aspancount += ubasestep; - - if (lcount) - { - lpdest = (short *) d_viewbuffer + pspanpackage->pdest; - lptex = pspanpackage->ptex; - lpz = pspanpackage->pz; - lsfrac = pspanpackage->sfrac; - ltfrac = pspanpackage->tfrac; - llight = pspanpackage->light; - lzi = pspanpackage->zi; - - do - { - if ((lzi >> 16) < *lpz) // hidden - { - count = 0; - goto skiploop16; - } -drawloop16: - *lpz++ = lzi >> 16; - *lpdest++ = ((short *)acolormap)[(llight & 0xFF00) | lptex[texscan[ltfrac >> 16] + (lsfrac >> 16)]]; - lzi += r_zistepx; - lsfrac += r_sstepx; - ltfrac += r_tstepx; - llight += r_lstepx; - } - while (--lcount); - goto done16; - - do - { - if ((lzi >> 16) >= *lpz) // draw - { - lsfrac += r_sstepx * count; - ltfrac += r_tstepx * count; - llight += r_lstepx * count; - lpdest += count; - goto drawloop16; - } -skiploop16: - count++; - lzi += r_zistepx; - lpz++; - } - while (--lcount); -done16: ; - } - - pspanpackage++; - } - while (pspanpackage->count != -999999); - } -} - -void -polyset_draw_spans_32 (spanpackage_t * pspanpackage) -{ - int i, j, texscantable[2*MAX_LBM_HEIGHT], *texscan; - // LordHavoc: compute skin row table - for (i = 0, j = -r_affinetridesc.skinheight * r_affinetridesc.skinwidth; - i < r_affinetridesc.skinheight*2;i++, j += r_affinetridesc.skinwidth) - texscantable[i] = j; - texscan = texscantable + r_affinetridesc.skinheight; - - { - int lcount, count = 0; - int *lpdest; - byte *lptex; - int lsfrac, ltfrac; - int llight; - int lzi; - short *lpz; - - do - { - lcount = d_aspancount - pspanpackage->count; - - errorterm += erroradjustup; - if (errorterm >= 0) - { - d_aspancount += d_countextrastep; - errorterm -= erroradjustdown; - } - else - d_aspancount += ubasestep; - - if (lcount) - { - lpdest = (int *) d_viewbuffer + pspanpackage->pdest; - lptex = pspanpackage->ptex; - lpz = pspanpackage->pz; - lsfrac = pspanpackage->sfrac; - ltfrac = pspanpackage->tfrac; - llight = pspanpackage->light; - lzi = pspanpackage->zi; - - do - { - if ((lzi >> 16) < *lpz) // hidden - { - count = 0; - goto skiploop32; - } -drawloop32: - *lpz++ = lzi >> 16; - *lpdest++ = - vid.colormap32[(llight & 0xFF00) | - lptex[texscan[ltfrac >> 16] + - (lsfrac >> 16)]]; - lzi += r_zistepx; - lsfrac += r_sstepx; - ltfrac += r_tstepx; - llight += r_lstepx; - } - while (--lcount); - goto done32; - - do - { - if ((lzi >> 16) >= *lpz) // draw - { - lsfrac += r_sstepx * count; - ltfrac += r_tstepx * count; - llight += r_lstepx * count; - lpdest += count; - goto drawloop32; - } -skiploop32: - count++; - lzi += r_zistepx; - lpz++; - } - while (--lcount); -done32: ; - } - - pspanpackage++; - } - while (pspanpackage->count != -999999); - } -} void D_RasterizeAliasPolySmooth (void) @@ -875,13 +701,7 @@ D_RasterizeAliasPolySmooth (void) d_pdestbasestep = screenwidth + ubasestep; d_pdestextrastep = d_pdestbasestep + 1; -#ifdef USE_INTEL_ASM - if (sw_ctx->pixbytes == 1) { - d_pdest = (int) d_viewbuffer + ystart * screenwidth + plefttop[0]; - } else -#endif - d_pdest = ystart * screenwidth + plefttop[0]; - + d_pdest = (byte *) d_viewbuffer + ystart * screenwidth + plefttop[0]; d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0]; // TODO: can reuse partial expressions here @@ -947,13 +767,7 @@ D_RasterizeAliasPolySmooth (void) d_pdestbasestep = screenwidth + ubasestep; d_pdestextrastep = d_pdestbasestep + 1; -#ifdef USE_INTEL_ASM - if (sw_ctx->pixbytes == 1) { - d_pdest = (int) d_viewbuffer + ystart * screenwidth + plefttop[0]; - } else -#endif - d_pdest = ystart * screenwidth + plefttop[0]; - + d_pdest = (byte *) d_viewbuffer + ystart * screenwidth + plefttop[0]; #ifdef USE_INTEL_ASM d_pzbasestep = (d_zwidth + ubasestep) << 1; d_pzextrastep = d_pzbasestep + 2; @@ -1010,7 +824,7 @@ D_RasterizeAliasPolySmooth (void) originalcount = a_spans[initialrightheight].count; a_spans[initialrightheight].count = -999999; // mark end of the // spanpackages - sw_ctx->draw->polyset_draw_spans (a_spans); + D_PolysetDrawSpans8 (a_spans); // scan out the bottom part of the right edge, if it exists if (pedgetable->numrightedges == 2) { @@ -1033,7 +847,7 @@ D_RasterizeAliasPolySmooth (void) d_countextrastep = ubasestep + 1; a_spans[initialrightheight + height].count = -999999; // mark end of the spanpackages - sw_ctx->draw->polyset_draw_spans (pstart); + D_PolysetDrawSpans8 (pstart); } } diff --git a/libs/video/renderer/sw/d_scan.c b/libs/video/renderer/sw/d_scan.c index 91b0d5a67..c411e8b1e 100644 --- a/libs/video/renderer/sw/d_scan.c +++ b/libs/video/renderer/sw/d_scan.c @@ -33,8 +33,6 @@ #include "d_local.h" #include "r_internal.h" -#include "vid_internal.h" -#include "vid_sw.h" byte *r_turb_pbase; byte *r_turb_pdest; @@ -49,7 +47,7 @@ int r_turb_spancount; the sine warp, to keep the edges from wrapping */ void -warp_screen_8 (void) +D_WarpScreen (void) { int w, h; int u, v; @@ -98,105 +96,6 @@ warp_screen_8 (void) } } -void -warp_screen_16 (void) -{ - int w, h; - int u, v; - int scr_x = vr_data.scr_view->xpos; - int scr_y = vr_data.scr_view->ylen; - int scr_w = vr_data.scr_view->xpos; - int scr_h = vr_data.scr_view->ylen; - short *dest; - int *turb; - int *col; - short **row; - short *rowptr[MAXHEIGHT]; - int column[MAXWIDTH]; - float wratio, hratio; - - w = r_refdef.vrect.width; - h = r_refdef.vrect.height; - - wratio = w / (float) scr_w; - hratio = h / (float) scr_h; - - for (v = 0; v < scr_h + AMP2 * 2; v++) { - rowptr[v] = (short *) d_viewbuffer + - (r_refdef.vrect.y * screenwidth) + - (screenwidth * (int) ((float) v * hratio * h / - (h + AMP2 * 2))); - } - - for (u = 0; u < scr_w + AMP2 * 2; u++) { - column[u] = r_refdef.vrect.x + - (int) ((float) u * wratio * w / (w + AMP2 * 2)); - } - - turb = intsintable + ((int) (vr_data.realtime * SPEED) & (CYCLE - 1)); - dest = (short *) vid.buffer + scr_y * (vid.rowbytes >> 1) + scr_x; - - for (v = 0; v < scr_h; v++, dest += (vid.rowbytes >> 1)) { - col = &column[turb[v]]; - row = &rowptr[v]; - for (u = 0; u < scr_w; u += 4) { - dest[u + 0] = row[turb[u + 0]][col[u + 0]]; - dest[u + 1] = row[turb[u + 1]][col[u + 1]]; - dest[u + 2] = row[turb[u + 2]][col[u + 2]]; - dest[u + 3] = row[turb[u + 3]][col[u + 3]]; - } - } -} - -void -warp_screen_32 (void) -{ - int w, h; - int u, v; - int scr_x = vr_data.scr_view->xpos; - int scr_y = vr_data.scr_view->ylen; - int scr_w = vr_data.scr_view->xpos; - int scr_h = vr_data.scr_view->ylen; - int *dest; - int *turb; - int *col; - int **row; - int *rowptr[MAXHEIGHT]; - int column[MAXWIDTH]; - float wratio, hratio; - - w = r_refdef.vrect.width; - h = r_refdef.vrect.height; - - wratio = w / (float) scr_w; - hratio = h / (float) scr_h; - - for (v = 0; v < scr_h + AMP2 * 2; v++) { - rowptr[v] = (int *) d_viewbuffer + - (r_refdef.vrect.y * screenwidth) + - (screenwidth * (int) ((float) v * hratio * h / - (h + AMP2 * 2))); - } - - for (u = 0; u < scr_w + AMP2 * 2; u++) { - column[u] = r_refdef.vrect.x + - (int) ((float) u * wratio * w / (w + AMP2 * 2)); - } - - turb = intsintable + ((int) (vr_data.realtime * SPEED) & (CYCLE - 1)); - dest = (int *) vid.buffer + scr_y * (vid.rowbytes >> 2) + scr_x; - - for (v = 0; v < scr_h; v++, dest += (vid.rowbytes >> 2)) { - col = &column[turb[v]]; - row = &rowptr[v]; - for (u = 0; u < scr_w; u += 4) { - dest[u + 0] = row[turb[u + 0]][col[u + 0]]; - dest[u + 1] = row[turb[u + 1]][col[u + 1]]; - dest[u + 2] = row[turb[u + 2]][col[u + 2]]; - dest[u + 3] = row[turb[u + 3]][col[u + 3]]; - } - } -} #ifdef PIC #undef USE_INTEL_ASM //XXX asm pic hack @@ -204,7 +103,7 @@ warp_screen_32 (void) #ifndef USE_INTEL_ASM void -draw_turbulent_span_8 (void) +D_DrawTurbulent8Span (void) { int sturb, tturb; @@ -222,41 +121,6 @@ draw_turbulent_span_8 (void) } #endif // !USE_INTEL_ASM -void -draw_turbulent_span_16 (void) -{ - int sturb, tturb; - short *pdest = (short *) r_turb_pdest; - - do { - sturb = ((r_turb_s + r_turb_turb[(r_turb_t >> 16) & - (CYCLE - 1)]) >> 16) & 63; - tturb = ((r_turb_t + r_turb_turb[(r_turb_s >> 16) & - (CYCLE - 1)]) >> 16) & 63; - *pdest++ = d_8to16table[r_turb_pbase[(tturb << 6) + sturb]]; - r_turb_s += r_turb_sstep; - r_turb_t += r_turb_tstep; - } while (--r_turb_spancount > 0); - r_turb_pdest = (byte *)pdest; -} - -void -draw_turbulent_span_32 (void) -{ - int sturb, tturb; - int *pdest = (int *) r_turb_pdest; - do { - sturb = ((r_turb_s + r_turb_turb[(r_turb_t >> 16) & - (CYCLE - 1)]) >> 16) & 63; - tturb = ((r_turb_t + r_turb_turb[(r_turb_s >> 16) & - (CYCLE - 1)]) >> 16) & 63; - *pdest++ = d_8to24table[r_turb_pbase[(tturb << 6) + sturb]]; - r_turb_s += r_turb_sstep; - r_turb_t += r_turb_tstep; - } while (--r_turb_spancount > 0); - r_turb_pdest = (byte *)pdest; -} - void Turbulent (espan_t *pspan) { @@ -372,7 +236,7 @@ Turbulent (espan_t *pspan) r_turb_s = r_turb_s & ((CYCLE << 16) - 1); r_turb_t = r_turb_t & ((CYCLE << 16) - 1); - sw_ctx->draw->draw_turbulent_span (); + D_DrawTurbulent8Span (); r_turb_s = snext; r_turb_t = tnext; @@ -384,7 +248,7 @@ Turbulent (espan_t *pspan) #ifndef USE_INTEL_ASM void -draw_spans_8 (espan_t *pspan) +D_DrawSpans8 (espan_t *pspan) { int count, spancount; unsigned char *pbase, *pdest; @@ -509,285 +373,6 @@ draw_spans_8 (espan_t *pspan) } #endif -void -draw_spans_16 (espan_t *pspan) -{ - short *pbase = (short *) cacheblock, *pdest; - int count; - fixed16_t s, t, snext, tnext, sstep, tstep; - float sdivz, tdivz, zi, z, du, dv; - float sdivz8stepu, tdivz8stepu, zi8stepu; - - sstep = 0; // keep compiler happy - tstep = 0; // ditto - - sdivz8stepu = d_sdivzstepu * 8; - tdivz8stepu = d_tdivzstepu * 8; - zi8stepu = d_zistepu * 8 * 65536; - - do { - pdest = (short *) d_viewbuffer + (screenwidth * pspan->v) + - pspan->u; - - count = pspan->count; - - // calculate the initial s/z, t/z, 1/z, s, and t and clamp - du = (float) pspan->u; - dv = (float) pspan->v; - - sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; - tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; - zi = (d_ziorigin + dv * d_zistepv + du * d_zistepu) * 65536.0f; - z = d_zitable[(unsigned short) zi]; - - s = (int) (sdivz * z) + sadjust; - s = bound(0, s, bbextents); - t = (int) (tdivz * z) + tadjust; - t = bound(0, t, bbextentt); - - while(count >= 8) { - count -= 8; - // calculate s/z, t/z, zi->fixed s and t at far end of span, - // calculate s and t steps across span by shifting - sdivz += sdivz8stepu; - tdivz += tdivz8stepu; - zi += zi8stepu; - z = d_zitable[(unsigned short) zi]; - - // prevent round-off error on <0 steps from from causing - // overstepping & running off the edge of the texture - snext = (int) (sdivz * z) + sadjust; - snext = bound(8, snext, bbextents); - tnext = (int) (tdivz * z) + tadjust; - tnext = bound(8, tnext, bbextentt); - - sstep = (snext - s) >> 3; - tstep = (tnext - t) >> 3; - - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[1] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[2] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[3] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[4] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[5] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[6] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[7] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s = snext;t = tnext; - pdest += 8; - } - if (count) - { - // calculate s/z, t/z, zi->fixed s and t at last pixel in span - // (so can't step off polygon), clamp, calculate s and t steps - // across span by division, biasing steps low so we don't run - // off the texture - //countminus1 = (float) (count - 1); - sdivz += d_sdivzstepu * count; //minus1; - tdivz += d_tdivzstepu * count; //minus1; - zi += d_zistepu * 65536.0f * count; //minus1; - z = d_zitable[(unsigned short) zi]; - - // prevent round-off error on <0 steps from from causing - // overstepping & running off the edge of the texture - snext = (int) (sdivz * z) + sadjust; - snext = bound(count, snext, bbextents); - tnext = (int) (tdivz * z) + tadjust; - tnext = bound(count, tnext, bbextentt); - - if (count > 1) { - sstep = (snext - s) / count; //(count - 1); - tstep = (tnext - t) / count; //(count - 1); - - if (count & 4) - { - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[1] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[2] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[3] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep;t += tstep; - pdest += 4; - } - if (count & 2) - { - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[1] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest += 2; - } - if (count & 1) - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - } - else - { - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - } - } - } while ((pspan = pspan->pnext) != NULL); -} - -void -draw_spans_32 (espan_t *pspan) -{ - int *pbase = (int *) cacheblock, *pdest; - int count; - fixed16_t s, t, snext, tnext, sstep, tstep; - float sdivz, tdivz, zi, z, du, dv; - float sdivz8stepu, tdivz8stepu, zi8stepu; - - sstep = 0; // keep compiler happy - tstep = 0; // ditto - - sdivz8stepu = d_sdivzstepu * 8; - tdivz8stepu = d_tdivzstepu * 8; - zi8stepu = d_zistepu * 8 * 65536; - - do { - pdest = (int *) d_viewbuffer + (screenwidth * pspan->v) + pspan->u; - - count = pspan->count; - - // calculate the initial s/z, t/z, 1/z, s, and t and clamp - du = (float) pspan->u; - dv = (float) pspan->v; - - sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; - tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; - zi = (d_ziorigin + dv * d_zistepv + du * d_zistepu) * 65536.0f; - z = d_zitable[(unsigned short) zi]; - - s = (int) (sdivz * z) + sadjust; - s = bound(0, s, bbextents); - t = (int) (tdivz * z) + tadjust; - t = bound(0, t, bbextentt); - - while(count >= 8) { - count -= 8; - // calculate s/z, t/z, zi->fixed s and t at far end of span, - // calculate s and t steps across span by shifting - sdivz += sdivz8stepu; - tdivz += tdivz8stepu; - zi += zi8stepu; - z = d_zitable[(unsigned short) zi]; - - // prevent round-off error on <0 steps from from causing - // overstepping & running off the edge of the texture - snext = (int) (sdivz * z) + sadjust; - snext = bound(8, snext, bbextents); - tnext = (int) (tdivz * z) + tadjust; - tnext = bound(8, tnext, bbextentt); - - sstep = (snext - s) >> 3; - tstep = (tnext - t) >> 3; - - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[1] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[2] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[3] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[4] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[5] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[6] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[7] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s = snext; - t = tnext; - pdest += 8; - } - if (count) - { - // calculate s/z, t/z, zi->fixed s and t at last pixel in span - // (so can't step off polygon), clamp, calculate s and t steps - // across span by division, biasing steps low so we don't run - // off the texture - //countminus1 = (float) (count - 1); - sdivz += d_sdivzstepu * count; //minus1; - tdivz += d_tdivzstepu * count; //minus1; - zi += d_zistepu * 65536.0f * count; //minus1; - z = d_zitable[(unsigned short) zi]; - - // prevent round-off error on <0 steps from from causing - // overstepping & running off the edge of the texture - snext = (int) (sdivz * z) + sadjust; - snext = bound(count, snext, bbextents); - tnext = (int) (tdivz * z) + tadjust; - tnext = bound(count, tnext, bbextentt); - - if (count > 1) { - sstep = (snext - s) / count; //(count - 1); - tstep = (tnext - t) / count; //(count - 1); - - if (count & 4) - { - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[1] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[2] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[3] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest += 4; - } - if (count & 2) - { - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest[1] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - s += sstep; - t += tstep; - pdest += 2; - } - if (count & 1) - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - } - else - { - pdest[0] = pbase[(t >> 16) * cachewidth + (s >> 16)]; - } - } - } while ((pspan = pspan->pnext) != NULL); -} - #ifndef USE_INTEL_ASM void D_DrawZSpans (espan_t *pspan) diff --git a/libs/video/renderer/sw/d_scana.S b/libs/video/renderer/sw/d_scana.S index aa3eb2112..6ca194e72 100644 --- a/libs/video/renderer/sw/d_scana.S +++ b/libs/video/renderer/sw/d_scana.S @@ -49,8 +49,8 @@ //---------------------------------------------------------------------- .align 4 -.globl C(draw_turbulent_span_8) -C(draw_turbulent_span_8): +.globl C(D_DrawTurbulent8Span) +C(D_DrawTurbulent8Span): pushl %ebp // preserve caller's stack frame pointer pushl %esi // preserve register variables pushl %edi diff --git a/libs/video/renderer/sw/d_sky.c b/libs/video/renderer/sw/d_sky.c index 88ee451f6..c6cd5832d 100644 --- a/libs/video/renderer/sw/d_sky.c +++ b/libs/video/renderer/sw/d_sky.c @@ -32,7 +32,6 @@ #include "d_local.h" #include "r_internal.h" -#include "vid_sw.h" #define SKY_SPAN_SHIFT 5 #define SKY_SPAN_MAX (1 << SKY_SPAN_SHIFT) @@ -66,7 +65,7 @@ D_Sky_uv_To_st (int u, int v, fixed16_t *s, fixed16_t *t) } void -draw_sky_scans_8 (espan_t *pspan) +D_DrawSkyScans (espan_t *pspan) { int count, spancount, u, v; unsigned char *pdest; @@ -134,141 +133,3 @@ draw_sky_scans_8 (espan_t *pspan) } while ((pspan = pspan->pnext) != NULL); } - -void -draw_sky_scans_16 (espan_t *pspan) -{ - int count, spancount, u, v; - short *pdest; - fixed16_t s, t, snext, tnext, sstep, tstep; - int spancountminus1; - - sstep = 0; // keep compiler happy - tstep = 0; // ditto - snext = 0; // ditto - tnext = 0; // ditto - - do { - pdest = (short *) d_viewbuffer + screenwidth * pspan->v + pspan->u; - - count = pspan->count; - - // calculate the initial s & t - u = pspan->u; - v = pspan->v; - D_Sky_uv_To_st (u, v, &s, &t); - - do { - if (count >= SKY_SPAN_MAX) - spancount = SKY_SPAN_MAX; - else - spancount = count; - - count -= spancount; - - if (count) { - u += spancount; - - // calculate s and t at far end of span, - // calculate s and t steps across span by shifting - D_Sky_uv_To_st (u, v, &snext, &tnext); - - sstep = (snext - s) >> SKY_SPAN_SHIFT; - tstep = (tnext - t) >> SKY_SPAN_SHIFT; - } else { - // calculate s and t at last pixel in span, - // calculate s and t steps across span by division - spancountminus1 = (float) (spancount - 1); - - if (spancountminus1 > 0) { - u += spancountminus1; - D_Sky_uv_To_st (u, v, &snext, &tnext); - - sstep = (snext - s) / spancountminus1; - tstep = (tnext - t) / spancountminus1; - } - } - - do { - *pdest++ = ((short *) r_skysource) - [((t & R_SKY_TMASK) >> 8) + ((s & R_SKY_SMASK) >> 16)]; - s += sstep; - t += tstep; - } while (--spancount > 0); - - s = snext; - t = tnext; - - } while (count > 0); - - } while ((pspan = pspan->pnext) != NULL); -} - -void -draw_sky_scans_32 (espan_t *pspan) -{ - int count, spancount, u, v; - int *pdest; - fixed16_t s, t, snext, tnext, sstep, tstep; - int spancountminus1; - - sstep = 0; // keep compiler happy - tstep = 0; // ditto - snext = 0; // ditto - tnext = 0; // ditto - - do { - pdest = (int *) d_viewbuffer + screenwidth * pspan->v + pspan->u; - - count = pspan->count; - - // calculate the initial s & t - u = pspan->u; - v = pspan->v; - D_Sky_uv_To_st (u, v, &s, &t); - - do { - if (count >= SKY_SPAN_MAX) - spancount = SKY_SPAN_MAX; - else - spancount = count; - - count -= spancount; - - if (count) { - u += spancount; - - // calculate s and t at far end of span, - // calculate s and t steps across span by shifting - D_Sky_uv_To_st (u, v, &snext, &tnext); - - sstep = (snext - s) >> SKY_SPAN_SHIFT; - tstep = (tnext - t) >> SKY_SPAN_SHIFT; - } else { - // calculate s and t at last pixel in span, - // calculate s and t steps across span by division - spancountminus1 = (float) (spancount - 1); - - if (spancountminus1 > 0) { - u += spancountminus1; - D_Sky_uv_To_st (u, v, &snext, &tnext); - - sstep = (snext - s) / spancountminus1; - tstep = (tnext - t) / spancountminus1; - } - } - - do { - *pdest++ = ((int *) r_skysource) - [((t & R_SKY_TMASK) >> 8) + ((s & R_SKY_SMASK) >> 16)]; - s += sstep; - t += tstep; - } while (--spancount > 0); - - s = snext; - t = tnext; - - } while (count > 0); - - } while ((pspan = pspan->pnext) != NULL); -} diff --git a/libs/video/renderer/sw/d_spr8.S b/libs/video/renderer/sw/d_spr8.S index 3043b36c2..fcda6abd6 100644 --- a/libs/video/renderer/sw/d_spr8.S +++ b/libs/video/renderer/sw/d_spr8.S @@ -95,8 +95,8 @@ LClampHigh5: #define pspans 4+16 .align 4 -.globl C(sprite_draw_spans_8) -C(sprite_draw_spans_8): +.globl C(D_SpriteDrawSpans) +C(D_SpriteDrawSpans): pushl %ebp // preserve caller's stack frame pushl %edi pushl %esi // preserve register variables diff --git a/libs/video/renderer/sw/d_sprite.c b/libs/video/renderer/sw/d_sprite.c index 64757b283..b4f35202f 100644 --- a/libs/video/renderer/sw/d_sprite.c +++ b/libs/video/renderer/sw/d_sprite.c @@ -32,8 +32,6 @@ #include "d_local.h" #include "r_internal.h" -#include "vid_internal.h" -#include "vid_sw.h" static int sprite_height; static int minindex, maxindex; @@ -47,7 +45,7 @@ static sspan_t *sprite_spans; #ifndef USE_INTEL_ASM void -sprite_draw_spans_8 (sspan_t *pspan) +D_SpriteDrawSpans (sspan_t *pspan) { int count, spancount, izistep; int izi; @@ -196,307 +194,6 @@ sprite_draw_spans_8 (sspan_t *pspan) } #endif -void -sprite_draw_spans_16 (sspan_t *pspan) -{ - int count, spancount, izistep; - int izi; - byte *pbase; - short *pdest; - fixed16_t s, t, snext, tnext, sstep, tstep; - float sdivz, tdivz, zi, z, du, dv, spancountminus1; - float sdivz8stepu, tdivz8stepu, zi8stepu; - byte btemp; - short *pz; - - sstep = 0; // keep compiler happy - tstep = 0; // ditto - - pbase = (byte *) cacheblock; - - sdivz8stepu = d_sdivzstepu * 8; - tdivz8stepu = d_tdivzstepu * 8; - zi8stepu = d_zistepu * 8 * 65536; - - // we count on FP exceptions being turned off to avoid range problems - izistep = (int) (d_zistepu * 0x8000 * 0x10000); - - do { - pdest = (short *) d_viewbuffer + screenwidth * pspan->v + pspan->u; - pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u; - - count = pspan->count; - - if (count <= 0) - goto NextSpan2; - - // calculate the initial s/z, t/z, 1/z, s, and t and clamp - du = (float) pspan->u; - dv = (float) pspan->v; - - sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; - tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; - zi = (d_ziorigin + dv * d_zistepv + du * d_zistepu) * 65536.0f; - z = d_zitable[(int) zi]; - // we count on FP exceptions being turned off to avoid range - // problems - izi = (int) (zi * 0x8000); - - s = (int) (sdivz * z) + sadjust; - if (s > bbextents) - s = bbextents; - else if (s < 0) - s = 0; - - t = (int) (tdivz * z) + tadjust; - if (t > bbextentt) - t = bbextentt; - else if (t < 0) - t = 0; - - do { - // calculate s and t at the far end of the span - if (count >= 8) - spancount = 8; - else - spancount = count; - - count -= spancount; - - if (count) { - // calculate s/z, t/z, zi->fixed s and t at far end of - // span, calculate s and t steps across span by shifting - sdivz += sdivz8stepu; - tdivz += tdivz8stepu; - zi += zi8stepu; - z = d_zitable[(int) zi]; - - snext = (int) (sdivz * z) + sadjust; - if (snext > bbextents) - snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 - // steps from causing overstepping - // & running off the texture's edge - - tnext = (int) (tdivz * z) + tadjust; - if (tnext > bbextentt) - tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on - // <0 steps - - sstep = (snext - s) >> 3; - tstep = (tnext - t) >> 3; - } else { - // calculate s/z, t/z, zi->fixed s and t at last pixel in - // span (so can't step off polygon), clamp, calculate s - // and t steps across span by division, biasing steps - // low so we don't run off the texture - spancountminus1 = (float) (spancount - 1); - sdivz += d_sdivzstepu * spancountminus1; - tdivz += d_tdivzstepu * spancountminus1; - zi += d_zistepu * 65536.0f * spancountminus1; - z = d_zitable[(int) zi]; - snext = (int) (sdivz * z) + sadjust; - if (snext > bbextents) - snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 - // steps from from causing - // overstepping & running off the - // edge of the texture - - tnext = (int) (tdivz * z) + tadjust; - if (tnext > bbextentt) - tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on - // <0 steps - - if (spancount > 1) { - sstep = (snext - s) / (spancount - 1); - tstep = (tnext - t) / (spancount - 1); - } - } - - do { - btemp = pbase[(s >> 16) + (t >> 16) * cachewidth]; - if (btemp != TRANSPARENT_COLOR) { - if (*pz <= (izi >> 16)) { - *pz = izi >> 16; - *pdest = d_8to16table[btemp]; - } - } - - izi += izistep; - pdest++; - pz++; - s += sstep; - t += tstep; - } while (--spancount > 0); - - s = snext; - t = tnext; - - } while (count > 0); - -NextSpan2: - pspan++; - - } while (pspan->count != DS_SPAN_LIST_END); -} - -void -sprite_draw_spans_32 (sspan_t *pspan) -{ - int count, spancount, izistep; - int izi; - byte *pbase; - int *pdest; - fixed16_t s, t, snext, tnext, sstep, tstep; - float sdivz, tdivz, zi, z, du, dv, spancountminus1; - float sdivz8stepu, tdivz8stepu, zi8stepu; - byte btemp; - short *pz; - - sstep = 0; // keep compiler happy - tstep = 0; // ditto - - pbase = (byte *) cacheblock; - - sdivz8stepu = d_sdivzstepu * 8; - tdivz8stepu = d_tdivzstepu * 8; - zi8stepu = d_zistepu * 8 * 65536; - - // we count on FP exceptions being turned off to avoid range problems - izistep = (int) (d_zistepu * 0x8000 * 0x10000); - - do { - pdest = (int *) d_viewbuffer + screenwidth * pspan->v + pspan->u; - pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u; - - count = pspan->count; - - if (count <= 0) - goto NextSpan4; - - // calculate the initial s/z, t/z, 1/z, s, and t and clamp - du = (float) pspan->u; - dv = (float) pspan->v; - - sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; - tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; - zi = (d_ziorigin + dv * d_zistepv + du * d_zistepu) * 65536.0f; - z = d_zitable[(int) zi]; - // we count on FP exceptions being turned off to avoid range - // problems - izi = (int) (zi * 0x8000); - - s = (int) (sdivz * z) + sadjust; - if (s > bbextents) - s = bbextents; - else if (s < 0) - s = 0; - - t = (int) (tdivz * z) + tadjust; - if (t > bbextentt) - t = bbextentt; - else if (t < 0) - t = 0; - - do { - // calculate s and t at the far end of the span - if (count >= 8) - spancount = 8; - else - spancount = count; - - count -= spancount; - - if (count) { - // calculate s/z, t/z, zi->fixed s and t at far end of - // span, calculate s and t steps across span by shifting - sdivz += sdivz8stepu; - tdivz += tdivz8stepu; - zi += zi8stepu; - z = d_zitable[(int) zi]; - - snext = (int) (sdivz * z) + sadjust; - if (snext > bbextents) - snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 - // steps from causing overstepping - // & running off the texture's edge - - tnext = (int) (tdivz * z) + tadjust; - if (tnext > bbextentt) - tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on - // <0 steps - - sstep = (snext - s) >> 3; - tstep = (tnext - t) >> 3; - } else { - // calculate s/z, t/z, zi->fixed s and t at last pixel in - // span (so can't step off polygon), clamp, calculate s - // and t steps across span by division, biasing steps low - // so we don't run off the texture - spancountminus1 = (float) (spancount - 1); - sdivz += d_sdivzstepu * spancountminus1; - tdivz += d_tdivzstepu * spancountminus1; - zi += d_zistepu * 65536.0f * spancountminus1; - z = d_zitable[(int) zi]; - snext = (int) (sdivz * z) + sadjust; - if (snext > bbextents) - snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 - // steps fromcausing overstepping - // & running off the texture's edge - - tnext = (int) (tdivz * z) + tadjust; - if (tnext > bbextentt) - tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on - // <0 steps - - if (spancount > 1) { - sstep = (snext - s) / (spancount - 1); - tstep = (tnext - t) / (spancount - 1); - } - } - - do { - btemp = pbase[(s >> 16) + (t >> 16) * cachewidth]; - if (btemp != TRANSPARENT_COLOR) { - if (*pz <= (izi >> 16)) { - *pz = izi >> 16; - *pdest = d_8to24table[btemp]; - } - } - - izi += izistep; - pdest++; - pz++; - s += sstep; - t += tstep; - } while (--spancount > 0); - - s = snext; - t = tnext; - - } while (count > 0); - -NextSpan4: - pspan++; - - } while (pspan->count != DS_SPAN_LIST_END); -} - static void D_SpriteScanLeftEdge (void) { @@ -715,5 +412,5 @@ D_DrawSprite (void) D_SpriteCalculateGradients (); D_SpriteScanLeftEdge (); D_SpriteScanRightEdge (); - sw_ctx->draw->sprite_draw_spans (sprite_spans); + D_SpriteDrawSpans (sprite_spans); } diff --git a/libs/video/renderer/sw/d_surf.c b/libs/video/renderer/sw/d_surf.c index c711a1a27..8e6e53c75 100644 --- a/libs/video/renderer/sw/d_surf.c +++ b/libs/video/renderer/sw/d_surf.c @@ -37,7 +37,6 @@ #include "compat.h" #include "d_local.h" #include "r_internal.h" -#include "vid_sw.h" float surfscale; @@ -70,7 +69,7 @@ D_SurfaceCacheForRes (void *data, int width, int height) if (pix > 64000) size += (pix - 64000) * 3; - return size * sw_ctx->pixbytes; + return size; } static void @@ -142,7 +141,7 @@ D_SCAlloc (int width, int size) if ((width < 0) || (width > 512)) // FIXME shouldn't really have a max Sys_Error ("D_SCAlloc: bad cache width %d", width); - if ((size <= 0) || (size > 0x40000 * sw_ctx->pixbytes)) // FIXME ditto + if ((size <= 0) || (size > 0x40000)) // FIXME ditto Sys_Error ("D_SCAlloc: bad cache size %d", size); // This adds the offset of data[0] in the surfcache_t struct. @@ -196,8 +195,7 @@ D_SCAlloc (int width, int size) new->width = width; // DEBUG if (width > 0) - new->height = (size - sizeof (*new) + sizeof (new->data)) / - (width * sw_ctx->pixbytes); + new->height = (size - sizeof (*new) + sizeof (new->data)) / width; new->owner = NULL; // should be set properly after return @@ -254,14 +252,14 @@ D_CacheSurface (msurface_t *surface, int miplevel) surfscale = 1.0 / (1 << miplevel); r_drawsurf.surfmip = miplevel; r_drawsurf.surfwidth = surface->extents[0] >> miplevel; - r_drawsurf.rowbytes = r_drawsurf.surfwidth * sw_ctx->pixbytes; + r_drawsurf.rowbytes = r_drawsurf.surfwidth; r_drawsurf.surfheight = surface->extents[1] >> miplevel; // allocate memory if needed if (!cache) { // if a texture just animated, don't reallocate it cache = D_SCAlloc (r_drawsurf.surfwidth, - r_drawsurf.rowbytes * r_drawsurf.surfheight); + r_drawsurf.surfwidth * r_drawsurf.surfheight); surface->cachespots[miplevel] = cache; cache->owner = &surface->cachespots[miplevel]; cache->mipscale = surfscale; diff --git a/libs/video/renderer/sw/d_zpoint.c b/libs/video/renderer/sw/d_zpoint.c index 1daf056ff..b7ed9e2bf 100644 --- a/libs/video/renderer/sw/d_zpoint.c +++ b/libs/video/renderer/sw/d_zpoint.c @@ -30,12 +30,10 @@ #include "d_local.h" #include "r_internal.h" -#include "vid_internal.h" -#include "vid_sw.h" void -draw_z_point_8 (void) +D_DrawZPoint (void) { byte *pdest; short *pz; @@ -50,35 +48,3 @@ draw_z_point_8 (void) *pdest = r_zpointdesc.color; } } - -void -draw_z_point_16 (void) -{ - short *pz; - int izi; - - pz = d_pzbuffer + (d_zwidth * r_zpointdesc.v) + r_zpointdesc.u; - izi = (int) (r_zpointdesc.zi * 0x8000); - - if (*pz <= izi) { - *pz = izi; - ((short *) d_viewbuffer) [d_scantable[r_zpointdesc.v] - + r_zpointdesc.u] = d_8to16table[r_zpointdesc.color]; - } -} - -void -draw_z_point_32 (void) -{ - short *pz; - int izi; - - pz = d_pzbuffer + (d_zwidth * r_zpointdesc.v) + r_zpointdesc.u; - izi = (int) (r_zpointdesc.zi * 0x8000); - - if (*pz <= izi) { - *pz = izi; - ((int *) d_viewbuffer) [d_scantable[r_zpointdesc.v] - + r_zpointdesc.u] = d_8to24table[r_zpointdesc.color]; - } -} diff --git a/libs/video/renderer/sw/draw.c b/libs/video/renderer/sw/draw.c index 1b6a9bcb0..c909dd293 100644 --- a/libs/video/renderer/sw/draw.c +++ b/libs/video/renderer/sw/draw.c @@ -47,7 +47,6 @@ #include "d_iface.h" #include "r_internal.h" #include "vid_internal.h" -#include "vid_sw.h" typedef struct { int width; @@ -243,88 +242,6 @@ Draw_Init (void) r_rectdesc.rowbytes = draw_backtile->width; } -void -draw_character_8 (int x, int y, byte *source, int drawline) -{ - byte *dest = ((byte*)vid.buffer) + y * vid.rowbytes + x; - - while (drawline--) { - if (source[0]) - dest[0] = source[0]; - if (source[1]) - dest[1] = source[1]; - if (source[2]) - dest[2] = source[2]; - if (source[3]) - dest[3] = source[3]; - if (source[4]) - dest[4] = source[4]; - if (source[5]) - dest[5] = source[5]; - if (source[6]) - dest[6] = source[6]; - if (source[7]) - dest[7] = source[7]; - source += 128; - dest += vid.rowbytes; - } -} - -void -draw_character_16 (int x, int y, byte *source, int drawline) -{ - uint16_t *dest = (uint16_t *) vid.buffer + y * (vid.rowbytes >> 1) + x; - - while (drawline--) { - if (source[0]) - dest[0] = d_8to16table[source[0]]; - if (source[1]) - dest[1] = d_8to16table[source[1]]; - if (source[2]) - dest[2] = d_8to16table[source[2]]; - if (source[3]) - dest[3] = d_8to16table[source[3]]; - if (source[4]) - dest[4] = d_8to16table[source[4]]; - if (source[5]) - dest[5] = d_8to16table[source[5]]; - if (source[6]) - dest[6] = d_8to16table[source[6]]; - if (source[7]) - dest[7] = d_8to16table[source[7]]; - - source += 128; - dest += (vid.rowbytes >> 1); - } -} - -void -draw_character_32 (int x, int y, byte *source, int drawline) -{ - uint32_t *dest = (uint32_t *) vid.buffer + y * (vid.rowbytes >> 2) + x; - - while (drawline--) { - if (source[0]) - dest[0] = d_8to24table[source[0]]; - if (source[1]) - dest[1] = d_8to24table[source[1]]; - if (source[2]) - dest[2] = d_8to24table[source[2]]; - if (source[3]) - dest[3] = d_8to24table[source[3]]; - if (source[4]) - dest[4] = d_8to24table[source[4]]; - if (source[5]) - dest[5] = d_8to24table[source[5]]; - if (source[6]) - dest[6] = d_8to24table[source[6]]; - if (source[7]) - dest[7] = d_8to24table[source[7]]; - - source += 128; - dest += (vid.rowbytes >> 2); - } -} /* Draw_Character @@ -336,6 +253,7 @@ draw_character_32 (int x, int y, byte *source, int drawline) inline void Draw_Character (int x, int y, unsigned int chr) { + byte *dest; byte *source; int drawline; int row, col; @@ -361,7 +279,28 @@ Draw_Character (int x, int y, unsigned int chr) } else drawline = 8; - sw_ctx->draw->draw_character (x, y, source, drawline); + dest = ((byte*)vid.buffer) + y * vid.rowbytes + x; + + while (drawline--) { + if (source[0]) + dest[0] = source[0]; + if (source[1]) + dest[1] = source[1]; + if (source[2]) + dest[2] = source[2]; + if (source[3]) + dest[3] = source[3]; + if (source[4]) + dest[4] = source[4]; + if (source[5]) + dest[5] = source[5]; + if (source[6]) + dest[6] = source[6]; + if (source[7]) + dest[7] = source[7]; + source += 128; + dest += vid.rowbytes; + } } @@ -394,8 +333,9 @@ Draw_AltString (int x, int y, const char *str) } } -void -draw_pixel_8 (int x, int y, byte color) + +static void +Draw_Pixel (int x, int y, byte color) { byte *dest; @@ -403,24 +343,6 @@ draw_pixel_8 (int x, int y, byte color) *dest = color; } -void -draw_pixel_16 (int x, int y, byte color) -{ - uint16_t *dest; - - dest = ((uint16_t*)vid.buffer) + y * vid.rowbytes + x; - *dest = d_8to16table[color]; -} - -void -draw_pixel_32 (int x, int y, byte color) -{ - uint32_t *dest; - - dest = ((uint32_t*)vid.buffer) + y * vid.rowbytes + x; - *dest = d_8to24table[color]; -} - static void crosshair_1 (int x, int y) { @@ -432,14 +354,14 @@ crosshair_2 (int x, int y) { byte c = crosshaircolor->int_val; - sw_ctx->draw->draw_pixel (x - 1, y, c); - sw_ctx->draw->draw_pixel (x - 3, y, c); - sw_ctx->draw->draw_pixel (x + 1, y, c); - sw_ctx->draw->draw_pixel (x + 3, y, c); - sw_ctx->draw->draw_pixel (x, y - 1, c); - sw_ctx->draw->draw_pixel (x, y - 3, c); - sw_ctx->draw->draw_pixel (x, y + 1, c); - sw_ctx->draw->draw_pixel (x, y + 3, c); + Draw_Pixel (x - 1, y, c); + Draw_Pixel (x - 3, y, c); + Draw_Pixel (x + 1, y, c); + Draw_Pixel (x + 3, y, c); + Draw_Pixel (x, y - 1, c); + Draw_Pixel (x, y - 3, c); + Draw_Pixel (x, y + 1, c); + Draw_Pixel (x, y + 3, c); } static void @@ -447,14 +369,14 @@ crosshair_3 (int x, int y) { byte c = crosshaircolor->int_val; - sw_ctx->draw->draw_pixel (x - 3, y - 3, c); - sw_ctx->draw->draw_pixel (x + 3, y - 3, c); - sw_ctx->draw->draw_pixel (x - 2, y - 2, c); - sw_ctx->draw->draw_pixel (x + 2, y - 2, c); - sw_ctx->draw->draw_pixel (x - 3, y + 3, c); - sw_ctx->draw->draw_pixel (x + 2, y + 2, c); - sw_ctx->draw->draw_pixel (x - 2, y + 2, c); - sw_ctx->draw->draw_pixel (x + 3, y + 3, c); + Draw_Pixel (x - 3, y - 3, c); + Draw_Pixel (x + 3, y - 3, c); + Draw_Pixel (x - 2, y - 2, c); + Draw_Pixel (x + 2, y - 2, c); + Draw_Pixel (x - 3, y + 3, c); + Draw_Pixel (x + 2, y + 2, c); + Draw_Pixel (x - 2, y + 2, c); + Draw_Pixel (x + 3, y + 3, c); } static void @@ -462,33 +384,33 @@ crosshair_4 (int x, int y) { //byte c = crosshaircolor->int_val; - sw_ctx->draw->draw_pixel (x, y - 2, 8); - sw_ctx->draw->draw_pixel (x + 1, y - 2, 9); + Draw_Pixel (x, y - 2, 8); + Draw_Pixel (x + 1, y - 2, 9); - sw_ctx->draw->draw_pixel (x, y - 1, 6); - sw_ctx->draw->draw_pixel (x + 1, y - 1, 8); - sw_ctx->draw->draw_pixel (x + 2, y - 1, 2); + Draw_Pixel (x, y - 1, 6); + Draw_Pixel (x + 1, y - 1, 8); + Draw_Pixel (x + 2, y - 1, 2); - sw_ctx->draw->draw_pixel (x - 2, y, 6); - sw_ctx->draw->draw_pixel (x - 1, y, 8); - sw_ctx->draw->draw_pixel (x, y, 8); - sw_ctx->draw->draw_pixel (x + 1, y, 6); - sw_ctx->draw->draw_pixel (x + 2, y, 8); - sw_ctx->draw->draw_pixel (x + 3, y, 8); + Draw_Pixel (x - 2, y, 6); + Draw_Pixel (x - 1, y, 8); + Draw_Pixel (x, y, 8); + Draw_Pixel (x + 1, y, 6); + Draw_Pixel (x + 2, y, 8); + Draw_Pixel (x + 3, y, 8); - sw_ctx->draw->draw_pixel (x - 1, y + 1, 2); - sw_ctx->draw->draw_pixel (x, y + 1, 8); - sw_ctx->draw->draw_pixel (x + 1, y + 1, 8); - sw_ctx->draw->draw_pixel (x + 2, y + 1, 2); - sw_ctx->draw->draw_pixel (x + 3, y + 1, 2); - sw_ctx->draw->draw_pixel (x + 4, y + 1, 2); + Draw_Pixel (x - 1, y + 1, 2); + Draw_Pixel (x, y + 1, 8); + Draw_Pixel (x + 1, y + 1, 8); + Draw_Pixel (x + 2, y + 1, 2); + Draw_Pixel (x + 3, y + 1, 2); + Draw_Pixel (x + 4, y + 1, 2); - sw_ctx->draw->draw_pixel (x, y + 2, 7); - sw_ctx->draw->draw_pixel (x + 1, y + 2, 8); - sw_ctx->draw->draw_pixel (x + 2, y + 2, 2); + Draw_Pixel (x, y + 2, 7); + Draw_Pixel (x + 1, y + 2, 8); + Draw_Pixel (x + 2, y + 2, 2); - sw_ctx->draw->draw_pixel (x + 1, y + 3, 2); - sw_ctx->draw->draw_pixel (x + 2, y + 3, 2); + Draw_Pixel (x + 1, y + 3, 2); + Draw_Pixel (x + 2, y + 3, 2); } static void @@ -496,29 +418,29 @@ crosshair_5 (int x, int y) { byte c = crosshaircolor->int_val; - sw_ctx->draw->draw_pixel (x - 1, y - 3, c); - sw_ctx->draw->draw_pixel (x + 0, y - 3, c); - sw_ctx->draw->draw_pixel (x + 1, y - 3, c); + Draw_Pixel (x - 1, y - 3, c); + Draw_Pixel (x + 0, y - 3, c); + Draw_Pixel (x + 1, y - 3, c); - sw_ctx->draw->draw_pixel (x - 2, y - 2, c); - sw_ctx->draw->draw_pixel (x + 2, y - 2, c); + Draw_Pixel (x - 2, y - 2, c); + Draw_Pixel (x + 2, y - 2, c); - sw_ctx->draw->draw_pixel (x - 3, y - 1, c); - sw_ctx->draw->draw_pixel (x + 3, y - 1, c); + Draw_Pixel (x - 3, y - 1, c); + Draw_Pixel (x + 3, y - 1, c); - sw_ctx->draw->draw_pixel (x - 3, y, c); - sw_ctx->draw->draw_pixel (x, y, c); - sw_ctx->draw->draw_pixel (x + 3, y, c); + Draw_Pixel (x - 3, y, c); + Draw_Pixel (x, y, c); + Draw_Pixel (x + 3, y, c); - sw_ctx->draw->draw_pixel (x - 3, y + 1, c); - sw_ctx->draw->draw_pixel (x + 3, y + 1, c); + Draw_Pixel (x - 3, y + 1, c); + Draw_Pixel (x + 3, y + 1, c); - sw_ctx->draw->draw_pixel (x - 2, y + 2, c); - sw_ctx->draw->draw_pixel (x + 2, y + 2, c); + Draw_Pixel (x - 2, y + 2, c); + Draw_Pixel (x + 2, y + 2, c); - sw_ctx->draw->draw_pixel (x - 1, y + 3, c); - sw_ctx->draw->draw_pixel (x + 0, y + 3, c); - sw_ctx->draw->draw_pixel (x + 1, y + 3, c); + Draw_Pixel (x - 1, y + 3, c); + Draw_Pixel (x + 0, y + 3, c); + Draw_Pixel (x + 1, y + 3, c); } static void (*crosshair_func[]) (int x, int y) = { @@ -559,11 +481,53 @@ Draw_CrosshairAt (int ch, int x, int y) void Draw_Pic (int x, int y, qpic_t *pic) { + byte *dest, *source, tbyte; + int v, u; + if (x < 0 || (x + pic->width) > vid.conview->xlen || y < 0 || (y + pic->height) > vid.conview->ylen) { Sys_MaskPrintf (SYS_vid, "Draw_Pic: bad coordinates"); + Draw_SubPic (x, y, pic, 0, 0, pic->width, pic->height); + return; + } + + source = pic->data; + + dest = ((byte*)vid.buffer) + y * vid.rowbytes + x; + + if (pic->width & 7) { // general + for (v = 0; v < pic->height; v++) { + for (u = 0; u < pic->width; u++) + if ((tbyte = source[u]) != TRANSPARENT_COLOR) + dest[u] = tbyte; + + dest += vid.rowbytes; + source += pic->width; + } + } else { // unwound + for (v = 0; v < pic->height; v++) { + for (u = 0; u < pic->width; u += 8) { + if ((tbyte = source[u]) != TRANSPARENT_COLOR) + dest[u] = tbyte; + if ((tbyte = source[u + 1]) != TRANSPARENT_COLOR) + dest[u + 1] = tbyte; + if ((tbyte = source[u + 2]) != TRANSPARENT_COLOR) + dest[u + 2] = tbyte; + if ((tbyte = source[u + 3]) != TRANSPARENT_COLOR) + dest[u + 3] = tbyte; + if ((tbyte = source[u + 4]) != TRANSPARENT_COLOR) + dest[u + 4] = tbyte; + if ((tbyte = source[u + 5]) != TRANSPARENT_COLOR) + dest[u + 5] = tbyte; + if ((tbyte = source[u + 6]) != TRANSPARENT_COLOR) + dest[u + 6] = tbyte; + if ((tbyte = source[u + 7]) != TRANSPARENT_COLOR) + dest[u + 7] = tbyte; + } + dest += vid.rowbytes; + source += pic->width; + } } - Draw_SubPic (x, y, pic, 0, 0, pic->width, pic->height); } void @@ -572,65 +536,13 @@ Draw_Picf (float x, float y, qpic_t *pic) Draw_Pic (x, y, pic); } -void -draw_subpic_8 (int x, int y, struct qpic_s *pic, int srcx, int srcy, - int width, int height) -{ - byte *source = pic->data + srcy * pic->width + srcx; - byte *dest = (byte *) vid.buffer + y * vid.rowbytes + x; - - for (int v = 0; v < height; v++) { - for (int u = 0; u < width; u++) { - byte tbyte = source[u]; - if (tbyte != TRANSPARENT_COLOR) { - dest[u] = tbyte; - } - } - dest += vid.rowbytes; - source += pic->width; - } -} - -void -draw_subpic_16 (int x, int y, struct qpic_s *pic, int srcx, int srcy, - int width, int height) -{ - byte *source = pic->data + srcy * pic->width + srcx; - uint16_t *dest = (uint16_t *) vid.buffer + y * (vid.rowbytes >> 1) + x; - for (int v = 0; v < height; v++) { - for (int u = 0; u < width; u++) { - byte tbyte = source[u]; - if (tbyte != TRANSPARENT_COLOR) { - dest[u] = d_8to16table[tbyte]; - } - } - dest += vid.rowbytes >> 1; - source += pic->width; - } -} - -void -draw_subpic_32 (int x, int y, struct qpic_s *pic, int srcx, int srcy, - int width, int height) -{ - byte *source = pic->data + srcy * pic->width + srcx; - uint32_t *dest = (uint32_t *) vid.buffer + y * (vid.rowbytes >> 2) + x; - for (int v = 0; v < height; v++) { - for (int u = 0; u < width; u++) { - byte tbyte = source[u]; - if (tbyte != TRANSPARENT_COLOR) { - dest[u] = d_8to24table[tbyte]; - } - } - dest += vid.rowbytes >> 2; - source += pic->width; - } -} - void Draw_SubPic (int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height) { + byte *dest, *source, tbyte; + int u, v; + if ((x < 0) || (x + width > vid.conview->xlen) || (y < 0) || (y + height > vid.conview->ylen)) { Sys_MaskPrintf (SYS_vid, "Draw_SubPic: bad coordinates"); @@ -657,23 +569,68 @@ Draw_SubPic (int x, int y, qpic_t *pic, int srcx, int srcy, int width, // next, clip to pic CLIP (srcx, srcy, width, height, pic->width, pic->height); - sw_ctx->draw->draw_subpic (x, y, pic, srcx, srcy, width, height); + source = pic->data + srcy * pic->width + srcx; + + dest = ((byte*)vid.buffer) + y * vid.rowbytes + x; + + if (width & 7) { // general + for (v = 0; v < height; v++) { + for (u = 0; u < width; u++) + if ((tbyte = source[u]) != TRANSPARENT_COLOR) + dest[u] = tbyte; + + dest += vid.rowbytes; + source += pic->width; + } + } else { // unwound + for (v = 0; v < height; v++) { + for (u = 0; u < width; u += 8) { + if ((tbyte = source[u]) != TRANSPARENT_COLOR) + dest[u] = tbyte; + if ((tbyte = source[u + 1]) != TRANSPARENT_COLOR) + dest[u + 1] = tbyte; + if ((tbyte = source[u + 2]) != TRANSPARENT_COLOR) + dest[u + 2] = tbyte; + if ((tbyte = source[u + 3]) != TRANSPARENT_COLOR) + dest[u + 3] = tbyte; + if ((tbyte = source[u + 4]) != TRANSPARENT_COLOR) + dest[u + 4] = tbyte; + if ((tbyte = source[u + 5]) != TRANSPARENT_COLOR) + dest[u + 5] = tbyte; + if ((tbyte = source[u + 6]) != TRANSPARENT_COLOR) + dest[u + 6] = tbyte; + if ((tbyte = source[u + 7]) != TRANSPARENT_COLOR) + dest[u + 7] = tbyte; + } + dest += vid.rowbytes; + source += pic->width; + } + } } -void -draw_console_background_8 (int lines, byte *data) -{ - byte *dest = vid.buffer; - for (int y = 0; y < lines; y++, dest += vid.rowbytes) { - int v = (vid.conview->ylen - lines + y) * 200 / vid.conview->ylen; - byte *src = data + v * 320; +void +Draw_ConsoleBackground (int lines, byte alpha) +{ + int x, y, v; + byte *src, *dest; + int f, fstep; + qpic_t *conback; + + conback = Draw_CachePic ("gfx/conback.lmp", false); + + // draw the pic + dest = vid.buffer; + + for (y = 0; y < lines; y++, dest += vid.rowbytes) { + v = (vid.conview->ylen - lines + y) * 200 / vid.conview->ylen; + src = conback->data + v * 320; if (vid.conview->xlen == 320) memcpy (dest, src, vid.conview->xlen); else { - int f = 0; - int fstep = 320 * 0x10000 / vid.conview->xlen; - for (int x = 0; x < vid.conview->xlen; x += 4) { + f = 0; + fstep = 320 * 0x10000 / vid.conview->xlen; + for (x = 0; x < vid.conview->xlen; x += 4) { dest[x] = src[f >> 16]; f += fstep; dest[x + 1] = src[f >> 16]; @@ -685,72 +642,13 @@ draw_console_background_8 (int lines, byte *data) } } } -} - -void -draw_console_background_16 (int lines, byte *data) -{ - uint16_t *dest = (uint16_t *) vid.buffer; - - for (int y = 0; y < lines; y++, dest += (vid.rowbytes >> 1)) { - // FIXME: pre-expand to native format? - // FIXME: does the endian switching go away in production? - int v = (vid.conview->ylen - lines + y) * 200 / vid.conview->ylen; - byte *src = data + v * 320; - int f = 0; - int fstep = 320 * 0x10000 / vid.conview->xlen; - for (int x = 0; x < vid.conview->xlen; x += 4) { - dest[x] = d_8to16table[src[f >> 16]]; - f += fstep; - dest[x + 1] = d_8to16table[src[f >> 16]]; - f += fstep; - dest[x + 2] = d_8to16table[src[f >> 16]]; - f += fstep; - dest[x + 3] = d_8to16table[src[f >> 16]]; - f += fstep; - } - } -} - -void -draw_console_background_32 (int lines, byte *data) -{ - uint32_t *dest = (uint32_t *) vid.buffer; - - for (int y = 0; y < lines; y++, dest += (vid.rowbytes >> 2)) { - // FIXME: pre-expand to native format? - // FIXME: does the endian switching go away in production? - int v = (vid.conview->ylen - lines + y) * 200 / vid.conview->ylen; - byte *src = data + v * 320; - int f = 0; - int fstep = 320 * 0x10000 / vid.conview->xlen; - for (int x = 0; x < vid.conview->xlen; x += 4) { - dest[x] = d_8to24table[src[f >> 16]]; - f += fstep; - dest[x + 1] = d_8to24table[src[f >> 16]]; - f += fstep; - dest[x + 2] = d_8to24table[src[f >> 16]]; - f += fstep; - dest[x + 3] = d_8to24table[src[f >> 16]]; - f += fstep; - } - } -} - -void -Draw_ConsoleBackground (int lines, byte alpha) -{ - qpic_t *conback = Draw_CachePic ("gfx/conback.lmp", false); - - // draw the pic - sw_ctx->draw->draw_console_background (lines, conback->data); Draw_AltString (vid.conview->xlen - strlen (cl_verstring->string) * 8 - 11, lines - 14, cl_verstring->string); } -void -draw_rect_8 (vrect_t *prect, int rowbytes, byte *psrc, int transparent) +static void +R_DrawRect (vrect_t *prect, int rowbytes, byte * psrc, int transparent) { byte t; int i, j, srcdelta, destdelta; @@ -785,223 +683,6 @@ draw_rect_8 (vrect_t *prect, int rowbytes, byte *psrc, int transparent) } } -void -draw_rect_16 (vrect_t *prect, int rowbytes, byte *psrc, int transparent) -{ - int i, j, srcdelta, destdelta; - uint16_t *pdest; - - pdest = (uint16_t *) vid.buffer + - (prect->y * (vid.rowbytes >> 1)) + prect->x; - - srcdelta = rowbytes - prect->width; - destdelta = (vid.rowbytes >> 1) - prect->width; - - if (transparent) { - for (i = 0; i < prect->height; i++) { - j = prect->width; - while(j >= 8) { - j -= 8; - if (psrc[0] != TRANSPARENT_COLOR) - pdest[0] = d_8to16table[psrc[0]]; - if (psrc[1] != TRANSPARENT_COLOR) - pdest[1] = d_8to16table[psrc[1]]; - if (psrc[2] != TRANSPARENT_COLOR) - pdest[2] = d_8to16table[psrc[2]]; - if (psrc[3] != TRANSPARENT_COLOR) - pdest[3] = d_8to16table[psrc[3]]; - if (psrc[4] != TRANSPARENT_COLOR) - pdest[4] = d_8to16table[psrc[4]]; - if (psrc[5] != TRANSPARENT_COLOR) - pdest[5] = d_8to16table[psrc[5]]; - if (psrc[6] != TRANSPARENT_COLOR) - pdest[6] = d_8to16table[psrc[6]]; - if (psrc[7] != TRANSPARENT_COLOR) - pdest[7] = d_8to16table[psrc[7]]; - psrc += 8; - pdest += 8; - } - if (j & 4) { - if (psrc[0] != TRANSPARENT_COLOR) - pdest[0] = d_8to16table[psrc[0]]; - if (psrc[1] != TRANSPARENT_COLOR) - pdest[1] = d_8to16table[psrc[1]]; - if (psrc[2] != TRANSPARENT_COLOR) - pdest[2] = d_8to16table[psrc[2]]; - if (psrc[3] != TRANSPARENT_COLOR) - pdest[3] = d_8to16table[psrc[3]]; - psrc += 4; - pdest += 4; - } - if (j & 2) { - if (psrc[0] != TRANSPARENT_COLOR) - pdest[0] = d_8to16table[psrc[0]]; - if (psrc[1] != TRANSPARENT_COLOR) - pdest[1] = d_8to16table[psrc[1]]; - psrc += 2; - pdest += 2; - } - if (j & 1) { - if (psrc[0] != TRANSPARENT_COLOR) - pdest[0] = d_8to16table[psrc[0]]; - psrc++; - pdest++; - } - - psrc += srcdelta; - pdest += destdelta; - } - } else { - for (i = 0; i < prect->height; - i++, psrc += srcdelta, pdest += destdelta) { - j = prect->width; - while(j >= 8) { - j -= 8; - pdest[0] = d_8to16table[psrc[0]]; - pdest[1] = d_8to16table[psrc[1]]; - pdest[2] = d_8to16table[psrc[2]]; - pdest[3] = d_8to16table[psrc[3]]; - pdest[4] = d_8to16table[psrc[4]]; - pdest[5] = d_8to16table[psrc[5]]; - pdest[6] = d_8to16table[psrc[6]]; - pdest[7] = d_8to16table[psrc[7]]; - psrc += 8; - pdest += 8; - } - if (j & 4) { - pdest[0] = d_8to16table[psrc[0]]; - pdest[1] = d_8to16table[psrc[1]]; - pdest[2] = d_8to16table[psrc[2]]; - pdest[3] = d_8to16table[psrc[3]]; - psrc += 4; - pdest += 4; - } - if (j & 2) { - pdest[0] = d_8to16table[psrc[0]]; - pdest[1] = d_8to16table[psrc[1]]; - psrc += 2; - pdest += 2; - } - if (j & 1) { - pdest[0] = d_8to16table[psrc[0]]; - psrc++; - pdest++; - } - } - } -} - -void -draw_rect_32 (vrect_t *prect, int rowbytes, byte *psrc, int transparent) -{ - int i, j, srcdelta, destdelta; - uint32_t *pdest; - - pdest = (uint32_t *)vid.buffer + prect->y * (vid.rowbytes >> 2) + prect->x; - - srcdelta = rowbytes - prect->width; - destdelta = (vid.rowbytes >> 2) - prect->width; - - if (transparent) { - for (i = 0; i < prect->height; i++) { - j = prect->width; - while(j >= 8) { - j -= 8; - if (psrc[0] != TRANSPARENT_COLOR) - pdest[0] = d_8to24table[psrc[0]]; - if (psrc[1] != TRANSPARENT_COLOR) - pdest[1] = d_8to24table[psrc[1]]; - if (psrc[2] != TRANSPARENT_COLOR) - pdest[2] = d_8to24table[psrc[2]]; - if (psrc[3] != TRANSPARENT_COLOR) - pdest[3] = d_8to24table[psrc[3]]; - if (psrc[4] != TRANSPARENT_COLOR) - pdest[4] = d_8to24table[psrc[4]]; - if (psrc[5] != TRANSPARENT_COLOR) - pdest[5] = d_8to24table[psrc[5]]; - if (psrc[6] != TRANSPARENT_COLOR) - pdest[6] = d_8to24table[psrc[6]]; - if (psrc[7] != TRANSPARENT_COLOR) - pdest[7] = d_8to24table[psrc[7]]; - psrc += 8; - pdest += 8; - } - if (j & 4) { - if (psrc[0] != TRANSPARENT_COLOR) - pdest[0] = d_8to24table[psrc[0]]; - if (psrc[1] != TRANSPARENT_COLOR) - pdest[1] = d_8to24table[psrc[1]]; - if (psrc[2] != TRANSPARENT_COLOR) - pdest[2] = d_8to24table[psrc[2]]; - if (psrc[3] != TRANSPARENT_COLOR) - pdest[3] = d_8to24table[psrc[3]]; - psrc += 4; - pdest += 4; - } - if (j & 2) { - if (psrc[0] != TRANSPARENT_COLOR) - pdest[0] = d_8to24table[psrc[0]]; - if (psrc[1] != TRANSPARENT_COLOR) - pdest[1] = d_8to24table[psrc[1]]; - psrc += 2; - pdest += 2; - } - if (j & 1) { - if (psrc[0] != TRANSPARENT_COLOR) - pdest[0] = d_8to24table[psrc[0]]; - psrc++; - pdest++; - } - - psrc += srcdelta; - pdest += destdelta; - } - } else { - for (i = 0; i < prect->height; - i++, psrc += srcdelta, pdest += destdelta) { - j = prect->width; - while(j >= 8) { - j -= 8; - pdest[0] = d_8to24table[psrc[0]]; - pdest[1] = d_8to24table[psrc[1]]; - pdest[2] = d_8to24table[psrc[2]]; - pdest[3] = d_8to24table[psrc[3]]; - pdest[4] = d_8to24table[psrc[4]]; - pdest[5] = d_8to24table[psrc[5]]; - pdest[6] = d_8to24table[psrc[6]]; - pdest[7] = d_8to24table[psrc[7]]; - psrc += 8; - pdest += 8; - } - if (j & 4) { - pdest[0] = d_8to24table[psrc[0]]; - pdest[1] = d_8to24table[psrc[1]]; - pdest[2] = d_8to24table[psrc[2]]; - pdest[3] = d_8to24table[psrc[3]]; - psrc += 4; - pdest += 4; - } - if (j & 2) { - pdest[0] = d_8to24table[psrc[0]]; - pdest[1] = d_8to24table[psrc[1]]; - psrc += 2; - pdest += 2; - } - if (j & 1) { - pdest[0] = d_8to24table[psrc[0]]; - psrc++; - pdest++; - } - } - } -} - -static void -R_DrawRect (vrect_t *prect, int rowbytes, byte *psrc, int transparent) -{ - sw_ctx->draw->draw_rect (prect, rowbytes, psrc, transparent); -} - /* Draw_TileClear @@ -1054,40 +735,6 @@ Draw_TileClear (int x, int y, int w, int h) } } -void -draw_fill_8 (int x, int y, int w, int h, int c) -{ - byte *dest = ((byte*)vid.buffer) + y * vid.rowbytes + x; - for (int v = 0; v < h; v++, dest += vid.rowbytes) { - for (int u = 0; u < w; u++) { - dest[u] = c; - } - } -} - -void -draw_fill_16 (int x, int y, int w, int h, int c) -{ - byte *dest = ((byte*)vid.buffer) + y * (vid.rowbytes >> 1) + x; - c = d_8to16table[c]; - for (int v = 0; v < h; v++, dest += vid.rowbytes >> 1) { - for (int u = 0; u < w; u++) { - dest[u] = c; - } - } -} - -void -draw_fill_32 (int x, int y, int w, int h, int c) -{ - byte *dest = ((byte*)vid.buffer) + y * (vid.rowbytes >> 2) + x; - c = d_8to24table[c]; - for (int v = 0; v < h; v++, dest += vid.rowbytes >> 2) { - for (int u = 0; u < w; u++) { - dest[u] = c; - } - } -} /* Draw_Fill @@ -1097,6 +744,9 @@ draw_fill_32 (int x, int y, int w, int h, int c) void Draw_Fill (int x, int y, int w, int h, int c) { + byte *dest; + int u, v; + if (x < 0 || x + w > vid.conview->xlen || y < 0 || y + h > vid.conview->ylen) { Sys_MaskPrintf (SYS_vid, "Bad Draw_Fill(%d, %d, %d, %d, %c)\n", @@ -1104,77 +754,40 @@ Draw_Fill (int x, int y, int w, int h, int c) } CLIP (x, y, w, h, (int) vid.width, (int) vid.height); - sw_ctx->draw->draw_fill (x, y, w, h, c); + dest = ((byte*)vid.buffer) + y * vid.rowbytes + x; + for (v = 0; v < h; v++, dest += vid.rowbytes) + for (u = 0; u < w; u++) + dest[u] = c; } -void -draw_fadescreen_8 (void) -{ - int height = vid.conview->ylen; - int width = vid.conview->xlen / 4; - int offset = vid.rowbytes; - uint32_t *pbuf; - - for (int y = 0; y < height; y++) { - uint32_t mask; - - pbuf = (uint32_t *) ((byte *)vid.buffer + offset * y); - mask = 0xff << ((y & 1) << 4); - - for (int x = 0; x < width; x++) { - *pbuf++ &= mask; - } - } -} - -void -draw_fadescreen_16 (void) -{ - int height = vid.conview->ylen; - int width = vid.conview->xlen / 4; - int offset = vid.rowbytes >> 1; - uint32_t *pbuf; - - for (int y = 0; y < height; y++) { - pbuf = (uint32_t *) ((byte *)vid.buffer + offset * y); - - for (int x = 0; x < width; x++, pbuf++) { - *pbuf = (*pbuf >> 1) & 0x7bef7bef; - } - } -} - -void -draw_fadescreen_32 (void) -{ - int height = vid.conview->ylen; - int width = vid.conview->xlen / 4; - int offset = vid.rowbytes >> 2; - uint32_t *pbuf; - - for (int y = 0; y < height; y++) { - pbuf = (uint32_t *) ((byte *)vid.buffer + offset * y); - - for (int x = 0; x < width; x++, pbuf++) { - *pbuf = (*pbuf >> 1) & 0x7f7f7f7f; - } - } -} void Draw_FadeScreen (void) { + int x, y; + int height = vid.conview->ylen; + int width = vid.conview->xlen / 4; + uint32_t *pbuf; S_ExtraUpdate (); - sw_ctx->draw->draw_fadescreen (); + for (y = 0; y < height; y++) { + uint32_t mask; + + pbuf = (uint32_t *) ((byte *)vid.buffer + vid.rowbytes * y); + mask = 0xff << ((y & 1) << 4); + + for (x = 0; x < width; x++) { + *pbuf++ &= mask; + } + } vr_data.scr_copyeverything = 1; S_ExtraUpdate (); } void -draw_blendscreen_8 (quat_t color) +Draw_BlendScreen (quat_t color) { int r, g, b, i; const byte *basepal; @@ -1200,73 +813,3 @@ draw_blendscreen_8 (quat_t color) } vid.vid_internal->set_palette (vid.vid_internal->data, pal); } - -void -draw_blendscreen_16 (quat_t color) -{ - int i, r, b; - int g1, g2; - unsigned x, y; - unsigned short rramp[32], gramp[64], bramp[32], *temp; - for (i = 0; i < 32; i++) { - r = i << 3; - g1 = i << 3; - g2 = g1 + 4; - b = i << 3; - - r += (int) (color[3] * (color[0] * 256 - r)); - g1 += (int) (color[3] * (color[1] - g1)); - g2 += (int) (color[3] * (color[1] - g2)); - b += (int) (color[3] * (color[2] - b)); - - rramp[i] = (vid.gammatable[r] << 8) & 0xF800; - gramp[i*2+0] = (vid.gammatable[g1] << 3) & 0x07E0; - gramp[i*2+1] = (vid.gammatable[g2] << 3) & 0x07E0; - bramp[i] = (vid.gammatable[b] >> 3) & 0x001F; - } - temp = vid.buffer; - for (y = 0;y < vid.height;y++, temp += (vid.rowbytes >> 1)) - for (x = 0;x < vid.width;x++) - temp[x] = rramp[(temp[x] & 0xF800) >> 11] - + gramp[(temp[x] & 0x07E0) >> 5] + bramp[temp[x] & 0x001F]; -} - -void -draw_blendscreen_32 (quat_t color) -{ - unsigned x, y; - int i, r, g, b; - - byte ramp[256][4], *temp; - for (i = 0; i < 256; i++) { - r = i; - g = i; - b = i; - - r += (int) (color[3] * (color[0] * 256 - r)); - g += (int) (color[3] * (color[1] * 256 - g)); - b += (int) (color[3] * (color[2] * 256 - b)); - - ramp[i][0] = vid.gammatable[r]; - ramp[i][1] = vid.gammatable[g]; - ramp[i][2] = vid.gammatable[b]; - ramp[i][3] = 0; - } - temp = vid.buffer; - for (y = 0; y < vid.height; y++, temp += vid.rowbytes) - { - for (x = 0;x < vid.width;x++) - { - temp[x*4+0] = ramp[temp[x*4+0]][0]; - temp[x*4+1] = ramp[temp[x*4+1]][1]; - temp[x*4+2] = ramp[temp[x*4+2]][2]; - temp[x*4+3] = 0; - } - } -} - -void -Draw_BlendScreen (quat_t color) -{ - sw_ctx->draw->draw_blendscreen (color); -} diff --git a/libs/video/renderer/sw/screen.c b/libs/video/renderer/sw/screen.c index 31daf43f3..30a60379e 100644 --- a/libs/video/renderer/sw/screen.c +++ b/libs/video/renderer/sw/screen.c @@ -37,8 +37,9 @@ #include "vid_sw.h" /* SCREEN SHOTS */ + tex_t * -capture_bgr_8 (void) +sw_SCR_CaptureBGR (void) { int count, x, y; tex_t *tex; @@ -65,21 +66,3 @@ capture_bgr_8 (void) } return tex; } - -tex_t * -capture_bgr_16 (void) -{ - return capture_bgr_8 ();//FIXME -} - -tex_t * -capture_bgr_32 (void) -{ - return capture_bgr_8 ();//FIXME -} - -tex_t * -sw_SCR_CaptureBGR (void) -{ - return sw_ctx->draw->capture_bgr (); -} diff --git a/libs/video/renderer/sw/surf8.S b/libs/video/renderer/sw/surf8.S index c112bf1f7..c15d2c689 100644 --- a/libs/video/renderer/sw/surf8.S +++ b/libs/video/renderer/sw/surf8.S @@ -55,8 +55,8 @@ C(R_Surf8Start): //---------------------------------------------------------------------- .align 4 -.globl C(R_DrawSurfaceBlock8_mip0) -C(R_DrawSurfaceBlock8_mip0): +.globl C(R_DrawSurfaceBlock_mip0) +C(R_DrawSurfaceBlock_mip0): pushl %ebp // preserve caller's stack frame pushl %edi pushl %esi // preserve register variables @@ -70,7 +70,7 @@ C(R_DrawSurfaceBlock8_mip0): movl %eax,sb_v movl C(prowdestbase),%edi - movl C(psource),%esi + movl C(pbasesource),%esi Lv_loop_mip0: @@ -256,8 +256,8 @@ LBPatch15: movl %edx,C(lightright) jc Lblockloop8_mip0 -// if (psource >= r_sourcemax) -// psource -= stepback; +// if (pbasesource >= r_sourcemax) +// pbasesource -= stepback; cmpl C(r_sourcemax),%esi jb LSkip_mip0 @@ -281,8 +281,8 @@ LSkip_mip0: //---------------------------------------------------------------------- .align 4 -.globl C(R_DrawSurfaceBlock8_mip1) -C(R_DrawSurfaceBlock8_mip1): +.globl C(R_DrawSurfaceBlock_mip1) +C(R_DrawSurfaceBlock_mip1): pushl %ebp // preserve caller's stack frame pushl %edi pushl %esi // preserve register variables @@ -296,7 +296,7 @@ C(R_DrawSurfaceBlock8_mip1): movl %eax,sb_v movl C(prowdestbase),%edi - movl C(psource),%esi + movl C(pbasesource),%esi Lv_loop_mip1: @@ -426,8 +426,8 @@ LBPatch29: jc Lblockloop8_mip1 -// if (psource >= r_sourcemax) -// psource -= stepback; +// if (pbasesource >= r_sourcemax) +// pbasesource -= stepback; cmpl C(r_sourcemax),%esi jb LSkip_mip1 @@ -451,8 +451,8 @@ LSkip_mip1: //---------------------------------------------------------------------- .align 4 -.globl C(R_DrawSurfaceBlock8_mip2) -C(R_DrawSurfaceBlock8_mip2): +.globl C(R_DrawSurfaceBlock_mip2) +C(R_DrawSurfaceBlock_mip2): pushl %ebp // preserve caller's stack frame pushl %edi pushl %esi // preserve register variables @@ -466,7 +466,7 @@ C(R_DrawSurfaceBlock8_mip2): movl %eax,sb_v movl C(prowdestbase),%edi - movl C(psource),%esi + movl C(pbasesource),%esi Lv_loop_mip2: @@ -566,8 +566,8 @@ LBPatch21: jc Lblockloop8_mip2 -// if (psource >= r_sourcemax) -// psource -= stepback; +// if (pbasesource >= r_sourcemax) +// pbasesource -= stepback; cmpl C(r_sourcemax),%esi jb LSkip_mip2 @@ -591,8 +591,8 @@ LSkip_mip2: //---------------------------------------------------------------------- .align 4 -.globl C(R_DrawSurfaceBlock8_mip3) -C(R_DrawSurfaceBlock8_mip3): +.globl C(R_DrawSurfaceBlock_mip3) +C(R_DrawSurfaceBlock_mip3): pushl %ebp // preserve caller's stack frame pushl %edi pushl %esi // preserve register variables @@ -606,7 +606,7 @@ C(R_DrawSurfaceBlock8_mip3): movl %eax,sb_v movl C(prowdestbase),%edi - movl C(psource),%esi + movl C(pbasesource),%esi Lv_loop_mip3: @@ -708,8 +708,8 @@ LBPatch31: addl %edx,%esi addl %ebp,%edi -// if (psource >= r_sourcemax) -// psource -= stepback; +// if (pbasesource >= r_sourcemax) +// pbasesource -= stepback; cmpl C(r_sourcemax),%esi jb LSkip_mip3 diff --git a/libs/video/renderer/sw/sw_graph.c b/libs/video/renderer/sw/sw_graph.c index edcecf9a4..4480a7eb7 100644 --- a/libs/video/renderer/sw/sw_graph.c +++ b/libs/video/renderer/sw/sw_graph.c @@ -33,21 +33,23 @@ #include "QF/render.h" #include "r_internal.h" -#include "vid_internal.h" -#include "vid_sw.h" +/* + R_LineGraph + + Called by only R_DisplayTime +*/ void -line_grapn_8 (int x, int y, int *h_vals, int count, int height) +R_LineGraph (int x, int y, int *h_vals, int count, int height) { int h, i, s, color; - int offset = vid.rowbytes; byte *dest; // FIXME: disable on no-buffer adapters, or put in the driver s = height; while (count--) { - dest = ((byte*)vid.buffer) + offset * y + x++; + dest = ((byte*)vid.buffer) + vid.rowbytes * y + x++; h = *h_vals++; @@ -63,80 +65,8 @@ line_grapn_8 (int x, int y, int *h_vals, int count, int height) if (h > s) h = s; - for (i = 0; i < h; i++, dest -= offset) { + for (i = 0; i < h; i++, dest -= vid.rowbytes) { dest[0] = color; } } } - -void -line_grapn_16 (int x, int y, int *h_vals, int count, int height) -{ - int h, i, s, color; - int offset = vid.rowbytes >> 1; - uint16_t *dest; - - // FIXME: disable on no-buffer adapters, or put in the driver - s = height; - - while (count--) { - dest = ((uint16_t*)vid.buffer) + offset * y + x++; - - h = *h_vals++; - - if (h == 10000) - color = d_8to16table[0x6f]; // yellow - else if (h == 9999) - color = d_8to16table[0x4f]; // red - else if (h == 9998) - color = d_8to16table[0xd0]; // blue - else - color = d_8to16table[0xff]; // pink - - if (h > s) - h = s; - - for (i = 0; i < h; i++, dest -= offset) { - dest[0] = color; - } - } -} - -void -line_grapn_32 (int x, int y, int *h_vals, int count, int height) -{ - int h, i, s, color; - int offset = vid.rowbytes >> 2; - uint32_t *dest; - - // FIXME: disable on no-buffer adapters, or put in the driver - s = height; - - while (count--) { - dest = ((uint32_t*)vid.buffer) + offset * y + x++; - - h = *h_vals++; - - if (h == 10000) - color = d_8to24table[0x6f]; // yellow - else if (h == 9999) - color = d_8to24table[0x4f]; // red - else if (h == 9998) - color = d_8to24table[0xd0]; // blue - else - color = d_8to24table[0xff]; // pink - - if (h > s) - h = s; - - for (i = 0; i < h; i++, dest -= offset) { - dest[0] = color; - } - } -} - -void -R_LineGraph (int x, int y, int *h_vals, int count, int height) -{ - sw_ctx->draw->line_grapn (x, y, h_vals, count, height); -} diff --git a/libs/video/renderer/sw/sw_ralias.c b/libs/video/renderer/sw/sw_ralias.c index 0158524e5..1899e2a47 100644 --- a/libs/video/renderer/sw/sw_ralias.c +++ b/libs/video/renderer/sw/sw_ralias.c @@ -39,7 +39,6 @@ #include "d_ifacea.h" #include "r_internal.h" -#include "vid_sw.h" #define LIGHT_MIN 5 // lowest light value we'll allow, to // avoid the need for inner-loop light @@ -564,12 +563,6 @@ R_AliasSetupSkin (entity_t *ent) r_affinetridesc.skinheight = pmdl->skinheight; acolormap = vid.colormap8; - if (sw_ctx->pixbytes != 1) { - if (sw_ctx->pixbytes == 2) - acolormap = vid.colormap16; - else - acolormap = vid.colormap32; - } if (ent->renderer.skin) { tex_t *base; @@ -662,12 +655,6 @@ R_AliasDrawModel (alight_t *plighting) if (!acolormap) acolormap = vid.colormap8; - if (acolormap == vid.colormap8 && sw_ctx->pixbytes != 1) { - if (sw_ctx->pixbytes == 2) - acolormap = vid.colormap16; - else - acolormap = vid.colormap32; - } if (r_affinetridesc.drawtype) { D_PolysetUpdateTables (); // FIXME: precalc... diff --git a/libs/video/renderer/sw/sw_rmain.c b/libs/video/renderer/sw/sw_rmain.c index 6b56f18eb..841036858 100644 --- a/libs/video/renderer/sw/sw_rmain.c +++ b/libs/video/renderer/sw/sw_rmain.c @@ -54,28 +54,11 @@ #include "mod_internal.h" #include "r_internal.h" #include "vid_internal.h" -#include "vid_sw.h" #ifdef PIC # undef USE_INTEL_ASM //XXX asm pic hack #endif -static sw_draw_t sw_draw_8 = { -#define SW_DRAW_FUNC(name, rettype, params) \ - .name = name##_8, -#include "vid_sw_draw.h" -}; -static sw_draw_t sw_draw_16 = { -#define SW_DRAW_FUNC(name, rettype, params) \ - .name = name##_16, -#include "vid_sw_draw.h" -}; -static sw_draw_t sw_draw_32 = { -#define SW_DRAW_FUNC(name, rettype, params) \ - .name = name##_32, -#include "vid_sw_draw.h" -}; - void *colormap; static vec3_t viewlightvec; static alight_t r_viewlighting = { 128, 192, viewlightvec }; @@ -134,15 +117,6 @@ sw_R_Init (void) { int dummy; - switch (sw_ctx->pixbytes) { - case 1: sw_ctx->draw = &sw_draw_8; break; - case 2: sw_ctx->draw = &sw_draw_16; break; - case 4: sw_ctx->draw = &sw_draw_32; break; - default: - Sys_Error("R_Init: unsupported pixbytes %i", - sw_ctx->pixbytes); - } - r_ent_queue = EntQueue_New (mod_num_types); // get stack position so we can guess if we are going to overflow @@ -832,7 +806,7 @@ R_RenderView_ (void) dp_time2 = Sys_DoubleTime (); if (r_dowarp) - sw_ctx->draw->warp_screen (); + D_WarpScreen (); if (r_timegraph->int_val) R_TimeGraph (); diff --git a/libs/video/renderer/sw/sw_rpart.c b/libs/video/renderer/sw/sw_rpart.c index 15928e633..a76d2d105 100644 --- a/libs/video/renderer/sw/sw_rpart.c +++ b/libs/video/renderer/sw/sw_rpart.c @@ -48,7 +48,6 @@ #include "compat.h" #include "r_internal.h" -#include "vid_sw.h" void R_DrawParticles (void) @@ -59,10 +58,9 @@ R_DrawParticles (void) R_RunParticles (vr_data.frametime); - void (*draw) (struct particle_s *particle) = sw_ctx->draw->draw_particle; for (unsigned i = 0; i < r_psystem.numparticles; i++) { particle_t *p = &r_psystem.particles[i]; - draw (p); + D_DrawParticle (p); } } diff --git a/libs/video/renderer/sw/sw_rsky.c b/libs/video/renderer/sw/sw_rsky.c index d67d0f375..b179ce420 100644 --- a/libs/video/renderer/sw/sw_rsky.c +++ b/libs/video/renderer/sw/sw_rsky.c @@ -28,13 +28,9 @@ # include "config.h" #endif -#include - #include "QF/render.h" #include "r_internal.h" -#include "vid_internal.h" -#include "vid_sw.h" static int iskyspeed = 8; @@ -51,12 +47,10 @@ int r_skymade; byte bottomsky[128 * 131]; byte bottommask[128 * 131]; -// sky and topsky both pack in here, 128 -// bytes of sky on the left of each scan, -// 128 bytes of topsky on the right, because -// the low-level drawers need 256-byte widths -byte skydata[128 * 256]; -byte skytex[128 * 256 * 4]; +byte newsky[128 * 256]; // newsky and topsky both pack in here, 128 + // bytes of newsky on the left of each scan, + // 128 bytes of topsky on the right, because + // the low-level drawers need 256-byte widths /* @@ -67,116 +61,116 @@ byte skytex[128 * 256 * 4]; void R_InitSky (texture_t *mt) { - memcpy (skydata, (byte *) mt + mt->offsets[0], 128 * 256); - r_skysource = skytex; + int i, j; + byte *src; + + src = (byte *) mt + mt->offsets[0]; + + for (i = 0; i < 128; i++) { + for (j = 0; j < 128; j++) { + newsky[(i * 256) + j + 128] = src[i * 256 + j + 128]; + } + } + + for (i = 0; i < 128; i++) { + for (j = 0; j < 131; j++) { + if (src[i * 256 + (j & 0x7F)]) { + bottomsky[(i * 131) + j] = src[i * 256 + (j & 0x7F)]; + bottommask[(i * 131) + j] = 0; + } else { + bottomsky[(i * 131) + j] = 0; + bottommask[(i * 131) + j] = 0xff; + } + } + } + + r_skysource = newsky; } + void -make_sky_8 (void) +R_MakeSky (void) { - int x, y, xshift1, yshift1, xshift2, yshift2; - byte *base1, *base2; + int x, y; + int ofs, baseofs; + int xshift, yshift; + byte *pnewsky; static int xlast = -1, ylast = -1; - xshift2 = r_skytime * r_skyspeed * 2.0f; - yshift2 = r_skytime * r_skyspeed * 2.0f; + xshift = r_skytime * r_skyspeed; + yshift = r_skytime * r_skyspeed; - if ((xshift2 == xlast) && (yshift2 == ylast)) + if ((xshift == xlast) && (yshift == ylast)) return; - xlast = xshift2; - ylast = yshift2; - xshift1 = xshift2 >> 1; - yshift1 = yshift2 >> 1; + xlast = xshift; + ylast = yshift; - byte *out = (byte *) skytex; - for (y = 0;y < 128;y++) - { - base1 = &skydata[((y + yshift1) & 127) * 256]; - base2 = &skydata[((y + yshift2) & 127) * 256 + 128]; - for (x = 0;x < 128;x++) - { - if (base1[(x + xshift1) & 127]) - *out = base1[(x + xshift1) & 127]; - else - *out = base2[(x + xshift2) & 127]; - out++; + pnewsky = &newsky[0]; + + for (y = 0; y < SKYSIZE; y++) { + baseofs = ((y + yshift) & SKYMASK) * 131; + for (x = 0; x < SKYSIZE; x++) { + ofs = baseofs + ((x + xshift) & SKYMASK); + + *pnewsky = (*(pnewsky + 128) & bottommask[ofs]) | bottomsky[ofs]; + pnewsky = pnewsky + 1; } - out += 128; + pnewsky += 128; } + r_skymade = 1; } -void -make_sky_16 (void) -{ - int x, y, xshift1, yshift1, xshift2, yshift2; - byte *base1, *base2; - static int xlast = -1, ylast = -1; - - xshift2 = r_skytime * r_skyspeed * 2.0f; - yshift2 = r_skytime * r_skyspeed * 2.0f; - - if ((xshift2 == xlast) && (yshift2 == ylast)) - return; - - xlast = xshift2; - ylast = yshift2; - xshift1 = xshift2 >> 1; - yshift1 = yshift2 >> 1; - - unsigned short *out = (unsigned short *) skytex; - for (y = 0;y < 128;y++) - { - base1 = &skydata[((y + yshift1) & 127) * 256]; - base2 = &skydata[((y + yshift2) & 127) * 256 + 128]; - for (x = 0;x < 128;x++) - { - if (base1[(x + xshift1) & 127]) - *out = d_8to16table[base1[(x + xshift1) & 127]]; - else - *out = d_8to16table[base2[(x + xshift2) & 127]]; - out++; - } - out += 128; - } - r_skymade = 1; -} void -make_sky_32 (void) +R_GenSkyTile (void *pdest) { - int x, y, xshift1, yshift1, xshift2, yshift2; - byte *base1, *base2; - static int xlast = -1, ylast = -1; + int x, y; + int ofs, baseofs; + int xshift, yshift; + unsigned int *pnewsky; + unsigned int *pd; - xshift2 = r_skytime * r_skyspeed * 2.0f; - yshift2 = r_skytime * r_skyspeed * 2.0f; + xshift = r_skytime * r_skyspeed; + yshift = r_skytime * r_skyspeed; - if ((xshift2 == xlast) && (yshift2 == ylast)) - return; + pnewsky = (unsigned int *) &newsky[0]; + pd = (unsigned int *) pdest; - xlast = xshift2; - ylast = yshift2; - xshift1 = xshift2 >> 1; - yshift1 = yshift2 >> 1; + for (y = 0; y < SKYSIZE; y++) { + baseofs = ((y + yshift) & SKYMASK) * 131; - unsigned int *out = (unsigned int *) skytex; - for (y = 0;y < 128;y++) { - base1 = &skydata[((y + yshift1) & 127) * 256]; - base2 = &skydata[((y + yshift2) & 127) * 256 + 128]; - for (x = 0;x < 128;x++) { - if (base1[(x + xshift1) & 127]) - *out = d_8to24table[base1[(x + xshift1) & 127]]; - else - *out = d_8to24table[base2[(x + xshift2) & 127]]; - out++; +// FIXME: clean this up +#if UNALIGNED_OK + for (x = 0; x < SKYSIZE; x += 4) { + ofs = baseofs + ((x + xshift) & SKYMASK); + + // PORT: unaligned dword access to bottommask and bottomsky + + *pd = (*(pnewsky + (128 / sizeof (unsigned int))) & + *(unsigned int *) &bottommask[ofs]) | + *(unsigned int *) &bottomsky[ofs]; + + pnewsky++; + pd++; } - out += 128; +#else + for (x = 0; x < SKYSIZE; x++) { + ofs = baseofs + ((x + xshift) & SKYMASK); + + *(byte *) pd = (*((byte *) pnewsky + 128) & + *(byte *) & bottommask[ofs]) | + *(byte *) & bottomsky[ofs]; + pnewsky = (unsigned int *) ((byte *) pnewsky + 1); + pd = (unsigned int *) ((byte *) pd + 1); + } +#endif + pnewsky += 128 / sizeof (unsigned int); } - r_skymade = 1; } + void R_SetSkyFrame (void) { diff --git a/libs/video/renderer/sw/sw_rsurf.c b/libs/video/renderer/sw/sw_rsurf.c index 3b968bd88..106dd8f29 100644 --- a/libs/video/renderer/sw/sw_rsurf.c +++ b/libs/video/renderer/sw/sw_rsurf.c @@ -1,5 +1,5 @@ /* - rsurf.c + sw_rsurf.c surface-related refresh code @@ -33,63 +33,43 @@ #include "QF/scene/entity.h" -#include "compat.h" #include "r_internal.h" -#include "vid_sw.h" + +#ifdef PIC +# undef USE_INTEL_ASM //XXX asm pic hack +#endif drawsurf_t r_drawsurf; -int sourcetstep; -static int lightleft, blocksize; +int sourcesstep, sourcetstep; +#ifndef USE_INTEL_ASM +static int lightleft; +#endif +static int blocksize; int lightdelta, lightdeltastep; int lightright, lightleftstep, lightrightstep, blockdivshift; static unsigned int blockdivmask; -byte *prowdestbase; -byte *psource; -int surfrowbytes; -unsigned int *r_lightptr; +void *prowdestbase; +unsigned char *pbasesource; +int surfrowbytes; // used by ASM files +unsigned int *r_lightptr; int r_stepback; int r_lightwidth; static int r_numhblocks; int r_numvblocks; -static byte *r_source; -byte *r_sourcemax; +static unsigned char *r_source; +unsigned char *r_sourcemax; -void R_DrawSurfaceBlock8_mip0 (void); -void R_DrawSurfaceBlock8_mip1 (void); -void R_DrawSurfaceBlock8_mip2 (void); -void R_DrawSurfaceBlock8_mip3 (void); -static void R_DrawSurfaceBlock16_mip0 (void); -static void R_DrawSurfaceBlock16_mip1 (void); -static void R_DrawSurfaceBlock16_mip2 (void); -static void R_DrawSurfaceBlock16_mip3 (void); -static void R_DrawSurfaceBlock32_mip0 (void); -static void R_DrawSurfaceBlock32_mip1 (void); -static void R_DrawSurfaceBlock32_mip2 (void); -static void R_DrawSurfaceBlock32_mip3 (void); +void R_DrawSurfaceBlock_mip0 (void); +void R_DrawSurfaceBlock_mip1 (void); +void R_DrawSurfaceBlock_mip2 (void); +void R_DrawSurfaceBlock_mip3 (void); -static void (*surfmiptable8[4]) (void) = { - R_DrawSurfaceBlock8_mip0, - R_DrawSurfaceBlock8_mip1, - R_DrawSurfaceBlock8_mip2, - R_DrawSurfaceBlock8_mip3 -}; +static void (*surfmiptable[4]) (void) = { + R_DrawSurfaceBlock_mip0, R_DrawSurfaceBlock_mip1, + R_DrawSurfaceBlock_mip2, R_DrawSurfaceBlock_mip3}; -static void (*surfmiptable16[4]) (void) = { - R_DrawSurfaceBlock16_mip0, - R_DrawSurfaceBlock16_mip1, - R_DrawSurfaceBlock16_mip2, - R_DrawSurfaceBlock16_mip3 -}; - -static void (*surfmiptable32[4]) (void) = { - R_DrawSurfaceBlock32_mip0, - R_DrawSurfaceBlock32_mip1, - R_DrawSurfaceBlock32_mip2, - R_DrawSurfaceBlock32_mip3 -}; - -static unsigned blocklights[34 * 34]; //FIXME make dynamic +static unsigned int blocklights[34 * 34]; //FIXME make dynamic static void @@ -202,30 +182,14 @@ R_BuildLightMap (void) if (surf->dlightframe == r_framecount) R_AddDynamicLights (); - /* - * JohnnyonFlame: - * 32 and 16bpp modes uses the positive lighting, unlike 8bpp - */ - switch (sw_ctx->pixbytes) { - case 1: - // bound, invert, and shift - for (i = 0; i < size; i++) { - t = (255 * 256 - blocklights[i]) >> (8 - VID_CBITS); + // bound, invert, and shift + for (i = 0; i < size; i++) { + t = (255 * 256 - (int) blocklights[i]) >> (8 - VID_CBITS); - if (t < (1 << 6)) - t = (1 << 6); + if (t < (1 << 6)) + t = (1 << 6); - blocklights[i] = t; - } - break; - default: - // LordHavoc: changed to positive (not inverse) lighting - for (i = 0; i < size; i++) { - t = bound(256, blocklights[i] >> (8 - VID_CBITS), - 256 * (VID_GRADES - 1)); - blocklights[i] = t; - } - break; + blocklights[i] = t; } } @@ -266,47 +230,34 @@ R_DrawSurface (void) //============================== + pblockdrawer = surfmiptable[r_drawsurf.surfmip]; + // TODO: needs to be set only when there is a display settings change + horzblockstep = blocksize; + smax = mt->width >> r_drawsurf.surfmip; twidth = texwidth; tmax = mt->height >> r_drawsurf.surfmip; sourcetstep = texwidth; r_stepback = tmax * twidth; + r_sourcemax = r_source + (tmax * smax); + soffset = r_drawsurf.surf->texturemins[0]; basetoffset = r_drawsurf.surf->texturemins[1]; - switch (sw_ctx->pixbytes) { - case 1: - pblockdrawer = surfmiptable8[r_drawsurf.surfmip]; - break; - case 2: - pblockdrawer = surfmiptable16[r_drawsurf.surfmip]; - break; - case 4: - pblockdrawer = surfmiptable32[r_drawsurf.surfmip]; - break; - default: - Sys_Error("R_DrawSurface: unsupported r_pixbytes %i", sw_ctx->pixbytes); - pblockdrawer = NULL; - } - - horzblockstep = blocksize * sw_ctx->pixbytes; - - r_sourcemax = r_source + (tmax * smax); - // << 16 components are to guarantee positive values for % - basetptr = r_source + (((basetoffset >> r_drawsurf.surfmip) + - (tmax << 16)) % tmax) * twidth; - soffset = (((soffset >> r_drawsurf.surfmip) + (smax << 16)) % smax); + soffset = ((soffset >> r_drawsurf.surfmip) + (smax << 16)) % smax; + basetptr = &r_source[((((basetoffset >> r_drawsurf.surfmip) + + (tmax << 16)) % tmax) * twidth)]; - pcolumndest = (byte *) r_drawsurf.surfdat; + pcolumndest = r_drawsurf.surfdat; for (u = 0; u < r_numhblocks; u++) { r_lightptr = blocklights + u; prowdestbase = pcolumndest; - psource = basetptr + soffset; + pbasesource = basetptr + soffset; (*pblockdrawer) (); @@ -318,16 +269,15 @@ R_DrawSurface (void) } } -//============================================================================= - #ifndef USE_INTEL_ASM void -R_DrawSurfaceBlock8_mip0 (void) +R_DrawSurfaceBlock_mip0 (void) { - int v, i, b, lightstep, light; - unsigned char pix, *prowdest; + int v, i, b, lightstep, lighttemp, light; + unsigned char pix, *psource, *prowdest; + psource = pbasesource; prowdest = prowdestbase; for (v = 0; v < r_numvblocks; v++) { @@ -340,13 +290,15 @@ R_DrawSurfaceBlock8_mip0 (void) lightrightstep = (r_lightptr[1] - lightright) >> 4; for (i = 0; i < 16; i++) { - lightstep = (lightleft - lightright) >> 4; + lighttemp = lightleft - lightright; + lightstep = lighttemp >> 4; light = lightright; for (b = 15; b >= 0; b--) { pix = psource[b]; - prowdest[b] = vid.colormap8[(light & 0xFF00) + pix]; + prowdest[b] = ((unsigned char *) vid.colormap8) + [(light & 0xFF00) + pix]; light += lightstep; } @@ -362,11 +314,12 @@ R_DrawSurfaceBlock8_mip0 (void) } void -R_DrawSurfaceBlock8_mip1 (void) +R_DrawSurfaceBlock_mip1 (void) { - int v, i, b, lightstep, light; - unsigned char pix, *prowdest; + int v, i, b, lightstep, lighttemp, light; + unsigned char pix, *psource, *prowdest; + psource = pbasesource; prowdest = prowdestbase; for (v = 0; v < r_numvblocks; v++) { @@ -379,13 +332,15 @@ R_DrawSurfaceBlock8_mip1 (void) lightrightstep = (r_lightptr[1] - lightright) >> 3; for (i = 0; i < 8; i++) { - lightstep = (lightleft - lightright) >> 3; + lighttemp = lightleft - lightright; + lightstep = lighttemp >> 3; light = lightright; for (b = 7; b >= 0; b--) { pix = psource[b]; - prowdest[b] = vid.colormap8[(light & 0xFF00) + pix]; + prowdest[b] = ((unsigned char *) vid.colormap8) + [(light & 0xFF00) + pix]; light += lightstep; } @@ -401,11 +356,12 @@ R_DrawSurfaceBlock8_mip1 (void) } void -R_DrawSurfaceBlock8_mip2 (void) +R_DrawSurfaceBlock_mip2 (void) { - int v, i, b, lightstep, light; - unsigned char pix, *prowdest; + int v, i, b, lightstep, lighttemp, light; + unsigned char pix, *psource, *prowdest; + psource = pbasesource; prowdest = prowdestbase; for (v = 0; v < r_numvblocks; v++) { @@ -418,13 +374,15 @@ R_DrawSurfaceBlock8_mip2 (void) lightrightstep = (r_lightptr[1] - lightright) >> 2; for (i = 0; i < 4; i++) { - lightstep = (lightleft - lightright) >> 2; + lighttemp = lightleft - lightright; + lightstep = lighttemp >> 2; light = lightright; for (b = 3; b >= 0; b--) { pix = psource[b]; - prowdest[b] = vid.colormap8[(light & 0xFF00) + pix]; + prowdest[b] = ((unsigned char *) vid.colormap8) + [(light & 0xFF00) + pix]; light += lightstep; } @@ -440,11 +398,12 @@ R_DrawSurfaceBlock8_mip2 (void) } void -R_DrawSurfaceBlock8_mip3 (void) +R_DrawSurfaceBlock_mip3 (void) { - int v, i, b, lightstep, light; - unsigned char pix, *prowdest; + int v, i, b, lightstep, lighttemp, light; + unsigned char pix, *psource, *prowdest; + psource = pbasesource; prowdest = prowdestbase; for (v = 0; v < r_numvblocks; v++) { @@ -457,13 +416,15 @@ R_DrawSurfaceBlock8_mip3 (void) lightrightstep = (r_lightptr[1] - lightright) >> 1; for (i = 0; i < 2; i++) { - lightstep = (lightleft - lightright) >> 1; + lighttemp = lightleft - lightright; + lightstep = lighttemp >> 1; light = lightright; for (b = 1; b >= 0; b--) { pix = psource[b]; - prowdest[b] = vid.colormap8[(light & 0xFF00) + pix]; + prowdest[b] = ((unsigned char *) vid.colormap8) + [(light & 0xFF00) + pix]; light += lightstep; } @@ -481,423 +442,33 @@ R_DrawSurfaceBlock8_mip3 (void) #endif static void -R_DrawSurfaceBlock16_mip0 (void) +R_GenTurbTile (byte *pbasetex, void *pdest) { - int k, v; - int lightstep, light; - unsigned short *prowdest; + int *turb; + int i, j, s, t; + byte *pd; - prowdest = (unsigned short *) prowdestbase; + turb = sintable + ((int) (vr_data.realtime * SPEED) & (CYCLE - 1)); + pd = (byte *) pdest; - for (v = 0; v < r_numvblocks; v++) - { - lightleft = r_lightptr[0]; - lightright = r_lightptr[1]; - r_lightptr += r_lightwidth; - lightleftstep = (r_lightptr[0] - lightleft) >> 4; - lightrightstep = (r_lightptr[1] - lightright) >> 4; - - for (k = 0; k < 16; k++) - { - light = lightleft; - lightstep = (lightright - lightleft) >> 4; - - prowdest[0] = vid.colormap16[(light & 0xFF00) + psource[0]]; - light += lightstep; - prowdest[1] = vid.colormap16[(light & 0xFF00) + psource[1]]; - light += lightstep; - prowdest[2] = vid.colormap16[(light & 0xFF00) + psource[2]]; - light += lightstep; - prowdest[3] = vid.colormap16[(light & 0xFF00) + psource[3]]; - light += lightstep; - prowdest[4] = vid.colormap16[(light & 0xFF00) + psource[4]]; - light += lightstep; - prowdest[5] = vid.colormap16[(light & 0xFF00) + psource[5]]; - light += lightstep; - prowdest[6] = vid.colormap16[(light & 0xFF00) + psource[6]]; - light += lightstep; - prowdest[7] = vid.colormap16[(light & 0xFF00) + psource[7]]; - light += lightstep; - prowdest[8] = vid.colormap16[(light & 0xFF00) + psource[8]]; - light += lightstep; - prowdest[9] = vid.colormap16[(light & 0xFF00) + psource[9]]; - light += lightstep; - prowdest[10] = vid.colormap16[(light & 0xFF00) + psource[10]]; - light += lightstep; - prowdest[11] = vid.colormap16[(light & 0xFF00) + psource[11]]; - light += lightstep; - prowdest[12] = vid.colormap16[(light & 0xFF00) + psource[12]]; - light += lightstep; - prowdest[13] = vid.colormap16[(light & 0xFF00) + psource[13]]; - light += lightstep; - prowdest[14] = vid.colormap16[(light & 0xFF00) + psource[14]]; - light += lightstep; - prowdest[15] = vid.colormap16[(light & 0xFF00) + psource[15]]; - - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 1); + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + s = (((j << 16) + turb[i & (CYCLE - 1)]) >> 16) & 63; + t = (((i << 16) + turb[j & (CYCLE - 1)]) >> 16) & 63; + *pd++ = *(pbasetex + (t << 6) + s); } - - if (psource >= r_sourcemax) - psource -= r_stepback; } } -static void -R_DrawSurfaceBlock16_mip1 (void) -{ - int k, v; - int lightstep, light; - unsigned short *prowdest; - - prowdest = (unsigned short *) prowdestbase; - - for (v = 0; v < r_numvblocks; v++) - { - lightleft = r_lightptr[0]; - lightright = r_lightptr[1]; - r_lightptr += r_lightwidth; - lightleftstep = (r_lightptr[0] - lightleft) >> 3; - lightrightstep = (r_lightptr[1] - lightright) >> 3; - - for (k = 0; k < 8; k++) - { - light = lightleft; - lightstep = (lightright - lightleft) >> 3; - - prowdest[0] = vid.colormap16[(light & 0xFF00) + psource[0]]; - light += lightstep; - prowdest[1] = vid.colormap16[(light & 0xFF00) + psource[1]]; - light += lightstep; - prowdest[2] = vid.colormap16[(light & 0xFF00) + psource[2]]; - light += lightstep; - prowdest[3] = vid.colormap16[(light & 0xFF00) + psource[3]]; - light += lightstep; - prowdest[4] = vid.colormap16[(light & 0xFF00) + psource[4]]; - light += lightstep; - prowdest[5] = vid.colormap16[(light & 0xFF00) + psource[5]]; - light += lightstep; - prowdest[6] = vid.colormap16[(light & 0xFF00) + psource[6]]; - light += lightstep; - prowdest[7] = vid.colormap16[(light & 0xFF00) + psource[7]]; - - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 1); - } - - if (psource >= r_sourcemax) - psource -= r_stepback; - } -} - -static void -R_DrawSurfaceBlock16_mip2 (void) -{ - int k, v; - int lightstep, light; - unsigned short *prowdest; - - prowdest = (unsigned short *) prowdestbase; - - for (v = 0; v < r_numvblocks; v++) - { - lightleft = r_lightptr[0]; - lightright = r_lightptr[1]; - r_lightptr += r_lightwidth; - lightleftstep = (r_lightptr[0] - lightleft) >> 2; - lightrightstep = (r_lightptr[1] - lightright) >> 2; - - for (k = 0; k < 4; k++) - { - light = lightleft; - lightstep = (lightright - lightleft) >> 2; - - prowdest[0] = vid.colormap16[(light & 0xFF00) + psource[0]]; - light += lightstep; - prowdest[1] = vid.colormap16[(light & 0xFF00) + psource[1]]; - light += lightstep; - prowdest[2] = vid.colormap16[(light & 0xFF00) + psource[2]]; - light += lightstep; - prowdest[3] = vid.colormap16[(light & 0xFF00) + psource[3]]; - - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 1); - } - - if (psource >= r_sourcemax) - psource -= r_stepback; - } -} - -static void -R_DrawSurfaceBlock16_mip3 (void) -{ - int v; - unsigned short *prowdest; - - prowdest = (unsigned short *) prowdestbase; - - for (v = 0; v < r_numvblocks; v++) - { - lightleft = r_lightptr[0]; - lightright = r_lightptr[1]; - r_lightptr += r_lightwidth; - lightleftstep = (r_lightptr[0] - lightleft) >> 1; - lightrightstep = (r_lightptr[1] - lightright) >> 1; - - prowdest[0] = vid.colormap16[(lightleft & 0xFF00) + psource[0]]; - prowdest[1] = vid.colormap16[(((lightleft + lightright) >> 1) & - 0xFF00) + psource[1]]; - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 1); - - prowdest[0] = vid.colormap16[(lightleft & 0xFF00) + psource[0]]; - prowdest[1] = vid.colormap16[(((lightleft + lightright) >> 1) & - 0xFF00) + psource[1]]; - psource += sourcetstep; - prowdest += (surfrowbytes >> 1); - - if (psource >= r_sourcemax) - psource -= r_stepback; - } -} - -static void -R_DrawSurfaceBlock32_mip0 (void) -{ - int k, v; - int lightstep, light; - unsigned int *prowdest; - - prowdest = (unsigned int *) prowdestbase; - - for (v = 0; v < r_numvblocks; v++) - { - lightleft = r_lightptr[0]; - lightright = r_lightptr[1]; - r_lightptr += r_lightwidth; - lightleftstep = (r_lightptr[0] - lightleft) >> 4; - lightrightstep = (r_lightptr[1] - lightright) >> 4; - - for (k = 0; k < 16; k++) - { - light = lightleft; - lightstep = (lightright - lightleft) >> 4; - - prowdest[0] = vid.colormap32[(light & 0xFF00) + psource[0]]; - light += lightstep; - prowdest[1] = vid.colormap32[(light & 0xFF00) + psource[1]]; - light += lightstep; - prowdest[2] = vid.colormap32[(light & 0xFF00) + psource[2]]; - light += lightstep; - prowdest[3] = vid.colormap32[(light & 0xFF00) + psource[3]]; - light += lightstep; - prowdest[4] = vid.colormap32[(light & 0xFF00) + psource[4]]; - light += lightstep; - prowdest[5] = vid.colormap32[(light & 0xFF00) + psource[5]]; - light += lightstep; - prowdest[6] = vid.colormap32[(light & 0xFF00) + psource[6]]; - light += lightstep; - prowdest[7] = vid.colormap32[(light & 0xFF00) + psource[7]]; - light += lightstep; - prowdest[8] = vid.colormap32[(light & 0xFF00) + psource[8]]; - light += lightstep; - prowdest[9] = vid.colormap32[(light & 0xFF00) + psource[9]]; - light += lightstep; - prowdest[10] = vid.colormap32[(light & 0xFF00) + psource[10]]; - light += lightstep; - prowdest[11] = vid.colormap32[(light & 0xFF00) + psource[11]]; - light += lightstep; - prowdest[12] = vid.colormap32[(light & 0xFF00) + psource[12]]; - light += lightstep; - prowdest[13] = vid.colormap32[(light & 0xFF00) + psource[13]]; - light += lightstep; - prowdest[14] = vid.colormap32[(light & 0xFF00) + psource[14]]; - light += lightstep; - prowdest[15] = vid.colormap32[(light & 0xFF00) + psource[15]]; - - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 2); - } - - if (psource >= r_sourcemax) - psource -= r_stepback; - } -} - -static void -R_DrawSurfaceBlock32_mip1 (void) -{ - int k, v; - int lightstep, light; - unsigned int *prowdest; - - prowdest = (unsigned int *) prowdestbase; - - for (v = 0; v < r_numvblocks; v++) - { - lightleft = r_lightptr[0]; - lightright = r_lightptr[1]; - r_lightptr += r_lightwidth; - lightleftstep = (r_lightptr[0] - lightleft) >> 3; - lightrightstep = (r_lightptr[1] - lightright) >> 3; - - for (k = 0; k < 8; k++) - { - light = lightleft; - lightstep = (lightright - lightleft) >> 3; - - prowdest[0] = vid.colormap32[(light & 0xFF00) + psource[0]]; - light += lightstep; - prowdest[1] = vid.colormap32[(light & 0xFF00) + psource[1]]; - light += lightstep; - prowdest[2] = vid.colormap32[(light & 0xFF00) + psource[2]]; - light += lightstep; - prowdest[3] = vid.colormap32[(light & 0xFF00) + psource[3]]; - light += lightstep; - prowdest[4] = vid.colormap32[(light & 0xFF00) + psource[4]]; - light += lightstep; - prowdest[5] = vid.colormap32[(light & 0xFF00) + psource[5]]; - light += lightstep; - prowdest[6] = vid.colormap32[(light & 0xFF00) + psource[6]]; - light += lightstep; - prowdest[7] = vid.colormap32[(light & 0xFF00) + psource[7]]; - - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 2); - } - - if (psource >= r_sourcemax) - psource -= r_stepback; - } -} - -static void -R_DrawSurfaceBlock32_mip2 (void) -{ - int k, v; - int lightstep, light; - unsigned int *prowdest; - - prowdest = (unsigned int *) prowdestbase; - - for (v = 0; v < r_numvblocks; v++) - { - lightleft = r_lightptr[0]; - lightright = r_lightptr[1]; - r_lightptr += r_lightwidth; - lightleftstep = (r_lightptr[0] - lightleft) >> 2; - lightrightstep = (r_lightptr[1] - lightright) >> 2; - - for (k = 0; k < 4; k++) - { - light = lightleft; - lightstep = (lightright - lightleft) >> 2; - - prowdest[0] = vid.colormap32[(light & 0xFF00) + psource[0]]; - light += lightstep; - prowdest[1] = vid.colormap32[(light & 0xFF00) + psource[1]]; - light += lightstep; - prowdest[2] = vid.colormap32[(light & 0xFF00) + psource[2]]; - light += lightstep; - prowdest[3] = vid.colormap32[(light & 0xFF00) + psource[3]]; - - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 2); - } - - if (psource >= r_sourcemax) - psource -= r_stepback; - } -} - -static void -R_DrawSurfaceBlock32_mip3 (void) -{ - int v; - unsigned int *prowdest; - - prowdest = (unsigned int *) prowdestbase; - - for (v = 0; v < r_numvblocks; v++) - { - lightleft = r_lightptr[0]; - lightright = r_lightptr[1]; - r_lightptr += r_lightwidth; - lightleftstep = (r_lightptr[0] - lightleft) >> 1; - lightrightstep = (r_lightptr[1] - lightright) >> 1; - - prowdest[0] = vid.colormap32[(lightleft & 0xFF00) + psource[0]]; - prowdest[1] = vid.colormap32[(((lightleft + lightright) >> 1) & - 0xFF00) + psource[1]]; - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 2); - - prowdest[0] = vid.colormap32[(lightleft & 0xFF00) + psource[0]]; - prowdest[1] = vid.colormap32[(((lightleft + lightright) >> 1) & - 0xFF00) + psource[1]]; - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 2); - - if (psource >= r_sourcemax) - psource -= r_stepback; - } -} - -/* void -R_DrawSurfaceBlock32 (void) +R_GenTile (msurface_t *psurf, void *pdest) { - int k, v; - int lightstep, light; - unsigned int *prowdest; - - prowdest = prowdestbase; - - for (v = 0; v < r_numvblocks; v++) { - - lightleft = r_lightptr[0]; - lightright = r_lightptr[1]; - r_lightptr += r_lightwidth; - lightleftstep = (r_lightptr[0] - lightleft) >> blockdivshift; - lightrightstep = (r_lightptr[1] - lightright) >> blockdivshift; - - for (k = 0; k < blocksize; k++) { - int b; - - lightstep = (lightright - lightleft) >> blockdivshift; - - light = lightleft; - - for (b = 0;b < blocksize;b++, light += lightstep) - prowdest[b] = vid.colormap32[(light & 0xFF00) + psource[b]]; - - psource += sourcetstep; - lightright += lightrightstep; - lightleft += lightleftstep; - prowdest += (surfrowbytes >> 2); - } - - if (psource >= r_sourcemax) - psource -= r_stepback; + if (psurf->flags & SURF_DRAWTURB) { + R_GenTurbTile (((byte *) psurf->texinfo->texture + + psurf->texinfo->texture->offsets[0]), pdest); + } else if (psurf->flags & SURF_DRAWSKY) { + R_GenSkyTile (pdest); + } else { + Sys_Error ("Unknown tile type"); } } -*/ diff --git a/libs/video/renderer/sw/vid_common_sw.c b/libs/video/renderer/sw/vid_common_sw.c index 554daeddb..f67a4ce8b 100644 --- a/libs/video/renderer/sw/vid_common_sw.c +++ b/libs/video/renderer/sw/vid_common_sw.c @@ -1,9 +1,9 @@ /* vid_common_sw.c - general video driver functions + Common software video driver functions - Copyright (C) 1996-1997 Id Software, Inc. + Copyright (C) 2001 Jeff Teunissen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -28,130 +28,11 @@ # include "config.h" #endif -#include "QF/cvar.h" +#include +#include + #include "QF/mathlib.h" -#include "QF/qargs.h" #include "QF/sys.h" -#include "QF/va.h" #include "QF/vid.h" -#include "compat.h" -#include "r_internal.h" #include "vid_internal.h" - -unsigned short d_8to16table[256]; - - -/* - VID_MakeColormap32 - - LordHavoc: makes a 32bit color*light table, RGBA order, no endian, - may need to be re-ordered to hardware at display time -*/ -static void -VID_MakeColormap32 (void *outcolormap, byte *pal) -{ - int c, l; - byte *out; - out = (byte *)&d_8to24table; - - /* - * Generates colors not affected by lighting, such as - * HUD pieces and general sprites (such as explosions) - */ - for (c = 0; c < 256; c++) { - *out++ = pal[c*3+2]; - *out++ = pal[c*3+1]; - *out++ = pal[c*3+0]; - *out++ = 255; - } - d_8to24table[255] = 0; // 255 is transparent - out = (byte *) outcolormap; - - /* - * Generates colors affected by lighting, such as the - * world and other models that give it life, like foes and pickups. - */ - for (l = 0;l < VID_GRADES;l++) - { - for (c = 0;c < vid.fullbright;c++) - { - out[(l*256+c)*4+0] = bound(0, (pal[c*3+2] * l) >> (VID_CBITS - 1), - 255); - out[(l*256+c)*4+1] = bound(0, (pal[c*3+1] * l) >> (VID_CBITS - 1), - 255); - out[(l*256+c)*4+2] = bound(0, (pal[c*3+0] * l) >> (VID_CBITS - 1), - 255); - out[(l*256+c)*4+3] = 255; - } - for (;c < 255;c++) - { - out[(l*256+c)*4+0] = pal[c*3+2]; - out[(l*256+c)*4+1] = pal[c*3+1]; - out[(l*256+c)*4+2] = pal[c*3+0]; - out[(l*256+c)*4+3] = 255; - } - out[(l*256+255)*4+0] = 0; - out[(l*256+255)*4+1] = 0; - out[(l*256+255)*4+2] = 0; - out[(l*256+255)*4+3] = 0; - } -} - -static unsigned short -lh24to16bit (int red, int green, int blue) -{ - red = bound(0, red, 255); - green = bound(0, green, 255); - blue = bound(0, blue, 255); - red >>= 3; - green >>= 2; - blue >>= 3; - red <<= 11; - green <<= 5; - return (unsigned short) (red | green | blue); -} - -/* - VID_MakeColormap16 - - LordHavoc: makes a 16bit color*light table, RGB order, native endian, - may need to be translated to hardware order at display time -*/ -static void -VID_MakeColormap16 (void *outcolormap, byte *pal) -{ - int c, l; - unsigned short *out; - out = (unsigned short *)&d_8to16table; - for (c = 0; c < 256; c++) - *out++ = lh24to16bit(pal[c*3+0], pal[c*3+1], pal[c*3+2]); - d_8to16table[255] = 0; // 255 is transparent - out = (unsigned short *) outcolormap; - for (l = 0;l < VID_GRADES;l++) - { - for (c = 0;c < vid.fullbright;c++) - out[l*256+c] = lh24to16bit( - (pal[c*3+0] * l) >> (VID_CBITS - 1), - (pal[c*3+1] * l) >> (VID_CBITS - 1), - (pal[c*3+2] * l) >> (VID_CBITS - 1)); - for (;c < 255;c++) - out[l*256+c] = lh24to16bit(pal[c*3+0], pal[c*3+1], pal[c*3+2]); - out[l*256+255] = 0; - } -} - -/* - VID_MakeColormaps - - LordHavoc: makes 8bit, 16bit, and 32bit colormaps and palettes -*/ -void -VID_MakeColormaps (void) -{ - vid.colormap16 = malloc (256*VID_GRADES * sizeof (unsigned short)); - vid.colormap32 = malloc (256*VID_GRADES * sizeof (unsigned int)); - SYS_CHECKMEM (vid.colormap16 && vid.colormap32); - VID_MakeColormap16(vid.colormap16, vid.palette); - VID_MakeColormap32(vid.colormap32, vid.palette); -} diff --git a/libs/video/targets/vid_win_sw.c b/libs/video/targets/vid_win_sw.c index 69e099b08..2303742e2 100644 --- a/libs/video/targets/vid_win_sw.c +++ b/libs/video/targets/vid_win_sw.c @@ -50,8 +50,6 @@ static win_palette_t st2d_8to32table[256]; static byte current_palette[768]; static int palette_changed; -static cvar_t *vid_bitdepth; - static LPDIRECTDRAW dd_Object; static HINSTANCE hInstDDraw; static LPDIRECTDRAWSURFACE dd_frontbuffer; @@ -476,27 +474,10 @@ Win_SW_Context (void) ctx->choose_visual = win_choose_visual; ctx->create_context = win_create_context; ctx->update = win_sw_update; -#if 0 //FIXME need to figure out 16 and 32 bit buffers - switch (vid_bitdepth->int_val) { - case 8: - ctx->pixbytes = 1; - break; - case 16: - ctx->pixbytes = 2; - break; - case 32: - ctx->pixbytes = 4; - break; - default: - Sys_Error ("X11_SW32_Context: unsupported bit depth"); - } -#endif return ctx; } void Win_SW_Init_Cvars (void) { - vid_bitdepth = Cvar_Get ("vid_bitdepth", "8", CVAR_ROM, NULL, "Sets " - "display bitdepth (supported modes: 8 16 32)"); } diff --git a/libs/video/targets/vid_x11_sw.c b/libs/video/targets/vid_x11_sw.c index 84588fb32..12dba8e49 100644 --- a/libs/video/targets/vid_x11_sw.c +++ b/libs/video/targets/vid_x11_sw.c @@ -69,8 +69,6 @@ int XShmGetEventBase (Display *x); // for broken X11 headers static GC x_gc; -static cvar_t *vid_bitdepth; - static qboolean doShm; static XShmSegmentInfo x_shminfo[2]; @@ -648,27 +646,11 @@ X11_SW_Context (void) ctx->set_palette = x11_set_palette; ctx->choose_visual = x11_choose_visual; ctx->create_context = x11_create_context; - - switch (vid_bitdepth->int_val) { - case 8: - ctx->pixbytes = 1; - break; - case 16: - ctx->pixbytes = 2; - break; - case 32: - ctx->pixbytes = 4; - break; - default: - Sys_Error ("X11_SW32_Context: unsupported bit depth"); - } + ctx->update = x11_sw8_update; return ctx; } void X11_SW_Init_Cvars (void) { -// FIXME: vid_colorbpp in common GL setup, make consistent with sdl32 scheme - vid_bitdepth = Cvar_Get ("vid_bitdepth", "8", CVAR_ROM, NULL, "Sets " - "display bitdepth (supported modes: 8 16 32)"); }