void MergeTexturesNormal (int nType, grsBitmap * bmBot, grsBitmap * bmTop, ubyte * dest_data) { ubyte * top_data, *bottom_data; int scale; if (gameOpts->ogl.bGlTexMerge && gameStates.render.textures.bGlsTexMergeOk) return; if (bmTop->bmProps.flags & BM_FLAG_RLE) bmTop = rle_expand_texture(bmTop); if (bmBot->bmProps.flags & BM_FLAG_RLE) bmBot = rle_expand_texture(bmBot); // Assert(bmBot != bmTop); top_data = bmTop->bmTexBuf; bottom_data = bmBot->bmTexBuf; scale = bmBot->bmProps.w / bmTop->bmProps.w; if (!scale) scale = 1; if (scale > 1) scale = scale; // Assert(bottom_data != top_data); switch(nType) { case 0: // Normal GrMergeTextures(bottom_data, top_data, dest_data, bmBot->bmProps.w, bmBot->bmProps.h, scale); break; case 1: GrMergeTextures1(bottom_data, top_data, dest_data, bmBot->bmProps.w, bmBot->bmProps.h, scale); break; case 2: GrMergeTextures2(bottom_data, top_data, dest_data, bmBot->bmProps.w, bmBot->bmProps.h, scale); break; case 3: GrMergeTextures3(bottom_data, top_data, dest_data, bmBot->bmProps.w, bmBot->bmProps.h, scale); break; } }
void MergeTextures ( int nType, grsBitmap * bmBot, grsBitmap * bmTop, grsBitmap *dest_bmp, int bSuperTransp) { tRGBA *c; int i, x, y, bw, bh, tw, th, dw, dh; int bTopBPP, bBtmBPP, bST = 0; frac topScale, btmScale; tRGBA *dest_data = (tRGBA *) dest_bmp->bmTexBuf; ubyte * top_data, *bottom_data, *top_pal, *btmPalette; bmBot = BmOverride (bmBot, -1); bmTop = BmOverride (bmTop, -1); if (gameOpts->ogl.bGlTexMerge && gameStates.render.textures.bGlsTexMergeOk) return; if (bmTop->bmProps.flags & BM_FLAG_RLE) bmTop = rle_expand_texture (bmTop); if (bmBot->bmProps.flags & BM_FLAG_RLE) bmBot = rle_expand_texture (bmBot); // Assert(bmBot != bmTop); top_data = bmTop->bmTexBuf; bottom_data = bmBot->bmTexBuf; top_pal = bmTop->bmPalette; btmPalette = bmBot->bmPalette; // Assert(bottom_data != top_data); //Int3(); bh = bw = bmBot->bmProps.w; //h = bmBot->bmProps.h; th = tw = bmTop->bmProps.w; dw = dh = dest_bmp->bmProps.w; //th = bmTop->bmProps.h; #if 1 // square textures assumed here, so no test for h! if (dw < tw) { topScale.c = tw / dw; topScale.d = 1; } else { topScale.c = 1; topScale.d = dw / tw; } if (dw < bw) { btmScale.c = bw / dw; btmScale.d = 1; } else { btmScale.c = dw / bw; btmScale.d = 1; } #else if (w > bmTop->bmProps.w) w = h = bmBot->bmProps.w; scale.c = scale.d = 1; #endif bTopBPP = bmTop->bmBPP; bBtmBPP = bmBot->bmBPP; #ifdef _DEBUG memset (dest_data, 253, dest_bmp->bmProps.w * dest_bmp->bmProps.h * 4); #endif switch(nType) { case 0: // Normal for (i = y = 0; y < dh; y++) for (x = 0; x < dw; x++, i++) { c = C (top_pal, top_data, tw * TOPSCALE (y) + TOPSCALE (x), bTopBPP, &bST); if (!(bST || c->a)) c = C (btmPalette, bottom_data, BTMIDX, bBtmBPP, &bST); dest_data [i] = *c; } break; case 1: // for (i = y = 0; y < dh; y++) for (x = 0; x < dw; x++, i++) { c = C (top_pal, top_data, tw * TOPSCALE (x) + th - 1 - TOPSCALE (y), bTopBPP, &bST); if (!(bST || c->a)) c = C (btmPalette, bottom_data, BTMIDX, bBtmBPP, &bST); dest_data [i] = *c; } break; case 2: // Normal for (i = y = 0; y < dh; y++) for (x = 0; x < dw; x++, i++) { c = C (top_pal, top_data, tw * (th - 1 - TOPSCALE (y)) + tw - 1 - TOPSCALE (x), bTopBPP, &bST); if (!(bST || c->a)) c = C (btmPalette, bottom_data, BTMIDX, bBtmBPP, &bST); dest_data [i] = *c; } break; case 3: // Normal for (i = y = 0; y < dh; y++) for (x = 0; x < dw; x++, i++) { c = C (top_pal, top_data, tw * (th - 1 - TOPSCALE (x)) + TOPSCALE (y), bTopBPP, &bST); if (!(bST || c->a)) c = C (btmPalette, bottom_data, BTMIDX, bBtmBPP, &bST); dest_data [i] = *c; } break; } }
// ------------------------------------------------------------------------------------- // Interface from Matt's data structures to Mike's texture mapper. // ------------------------------------------------------------------------------------- void draw_tmap(grs_bitmap *bp,int nverts,g3s_point **vertbuf) { int i; // These variables are used in system which renders texture maps which lie on one scanline as a line. // fix div_numerator; int lighting_on_save = Lighting_on; Assert(nverts <= MAX_TMAP_VERTS); #ifdef USE_MULT_CODE if ( !divide_table_filled ) fill_divide_table(); #endif // -- now called from g3_start_frame -- init_interface_vars_to_assembler(); // If no transparency and seg depth is large, render as flat shaded. if ((Current_seg_depth > Max_linear_depth) && ((bp->bm_flags & 3) == 0)) { draw_tmap_flat(bp, nverts, vertbuf); return; } if ( bp->bm_flags & BM_FLAG_RLE ) bp = rle_expand_texture( bp ); // Expand if rle'd Transparency_on = bp->bm_flags & BM_FLAG_TRANSPARENT; if (bp->bm_flags & BM_FLAG_NO_LIGHTING) Lighting_on = 0; // Setup texture map in Tmap1 Tmap1.nv = nverts; // Initialize number of vertices // div_numerator = DivNum; //f1_0*3; for (i=0; i<nverts; i++) { g3ds_vertex *tvp = &Tmap1.verts[i]; g3s_point *vp = vertbuf[i]; tvp->x2d = vp->p3_sx; tvp->y2d = vp->p3_sy; // Check for overflow on fixdiv. Will overflow on vp->z <= something small. Allow only as low as 256. if (vp->p3_z < 256) { vp->p3_z = 256; // Int3(); // we would overflow if we divided! } tvp->z = fixdiv(F1_0*12, vp->p3_z); tvp->u = vp->p3_u << 6; //* bp->bm_w; tvp->v = vp->p3_v << 6; //* bp->bm_h; Assert(Lighting_on < 3); if (Lighting_on) tvp->l = vp->p3_l * NUM_LIGHTING_LEVELS; } Lighting_enabled = Lighting_on; // Now, call my texture mapper. if (Lighting_on) { switch (Interpolation_method) { // 0 = choose, 1 = linear, 2 = /8 perspective, 3 = full perspective case 0: // choose best interpolation per2_flag = 1; if (Current_seg_depth > Max_perspective_depth) ntexture_map_lighted_linear(bp, &Tmap1); else ntexture_map_lighted(bp, &Tmap1); break; case 1: // linear interpolation per2_flag = 1; ntexture_map_lighted_linear(bp, &Tmap1); break; case 2: // perspective every 8th pixel interpolation per2_flag = 1; ntexture_map_lighted(bp, &Tmap1); break; case 3: // perspective every pixel interpolation per2_flag = 0; // this hack means do divide every pixel ntexture_map_lighted(bp, &Tmap1); break; default: Assert(0); // Illegal value for Interpolation_method, must be 0,1,2,3 } } else { switch (Interpolation_method) { // 0 = choose, 1 = linear, 2 = /8 perspective, 3 = full perspective case 0: // choose best interpolation per2_flag = 1; if (Current_seg_depth > Max_perspective_depth) ntexture_map_lighted_linear(bp, &Tmap1); else ntexture_map_lighted(bp, &Tmap1); break; case 1: // linear interpolation per2_flag = 1; ntexture_map_lighted_linear(bp, &Tmap1); break; case 2: // perspective every 8th pixel interpolation per2_flag = 1; ntexture_map_lighted(bp, &Tmap1); break; case 3: // perspective every pixel interpolation per2_flag = 0; // this hack means do divide every pixel ntexture_map_lighted(bp, &Tmap1); break; default: Assert(0); // Illegal value for Interpolation_method, must be 0,1,2,3 } } Lighting_on = lighting_on_save; }
int PixelTranspType (short nTexture, short nOrient, short nFrame, fix u, fix v) { CBitmap *bmP; int bmx, bmy, w, h, offs; ubyte c; #if 0 tBitmapIndex *bmiP; bmiP = gameData.pig.tex.bmIndexP + (nTexture); LoadBitmap (*bmiP, gameStates.app.bD1Data); bmP = BmOverride (gameData.pig.tex.bitmapP + bmiP->index); #else bmP = LoadFaceBitmap (nTexture, nFrame); if (!bmP->Buffer ()) return 0; #endif if (bmP->Flags () & BM_FLAG_RLE) bmP = rle_expand_texture (bmP); w = bmP->Width (); h = ((bmP->Type () == BM_TYPE_ALT) && bmP->Frames ()) ? w : bmP->Height (); if (nOrient == 0) { bmx = ((unsigned) X2I (u * w)) % w; bmy = ((unsigned) X2I (v * h)) % h; } else if (nOrient == 1) { bmx = ((unsigned) X2I ((I2X (1) - v) * w)) % w; bmy = ((unsigned) X2I (u * h)) % h; } else if (nOrient == 2) { bmx = ((unsigned) X2I ((I2X (1) - u) * w)) % w; bmy = ((unsigned) X2I ((I2X (1) - v) * h)) % h; } else { bmx = ((unsigned) X2I (v * w)) % w; bmy = ((unsigned) X2I ((I2X (1) - u) * h)) % h; } offs = bmy * w + bmx; if (bmP->Flags () & BM_FLAG_TGA) { ubyte *p; if (bmP->BPP () == 3) //no alpha -> no transparency return 0; p = bmP->Buffer () + offs * bmP->BPP (); // check super transparency color #if 1 if ((p [0] == 120) && (p [1] == 88) && (p [2] == 128)) #else if ((gameOpts->ogl.bGlTexMerge) ? (p [3] == 1) : ((p [0] == 120) && (p [1] == 88) && (p [2] == 128))) #endif return -1; // check alpha if (!p [3]) return 1; } else { c = bmP->Buffer () [offs]; if (c == SUPER_TRANSP_COLOR) return -1; if (c == TRANSPARENCY_COLOR) return 1; } return 0; }
// ------------------------------------------------------------------------------------- // Interface from Matt's data structures to Mike's texture mapper. // ------------------------------------------------------------------------------------- void draw_tmap(grs_bitmap *bp,int nverts,g3s_point **vertbuf) { int i; // These variables are used in system which renders texture maps which lie on one scanline as a line. #if SC2000K int flat_flag; // Set to 1 and remains 1 so long as all y coords are the same (in integer portion). int last_y; // Y coordinate of previous vertex. fix min_x = 0xfff0000, max_x = 0; // Minimum and maximum bounds of line to render in place of flat texture map. #endif // fix div_numerator; int lighting_on_save = Lighting_on; Assert(nverts <= MAX_TMAP_VERTS); #ifdef USE_MULT_CODE if ( !divide_table_filled ) fill_divide_table(); #endif // -- now called from g3_start_frame -- init_interface_vars_to_assembler(); // If no transparency and seg depth is large, render as flat shaded. if ((Current_seg_depth > Max_linear_depth) && ((bp->bm_flags & 3) == 0)) { draw_tmap_flat(bp, nverts, vertbuf); return; } if ( bp->bm_flags & BM_FLAG_RLE ) bp = rle_expand_texture( bp ); // Expand if rle'd Transparency_on = bp->bm_flags & BM_FLAG_TRANSPARENT; if (bp->bm_flags & BM_FLAG_NO_LIGHTING) Lighting_on = 0; // Set selector for current texture map. if ( bp->bm_selector == 0 ) { if (gr_bitmap_assign_selector( bp ) ) Error( "Couldn't assign selector in ntmap.c!\n" ); } pixel_data_selector = bp->bm_selector; // Setup texture map in Tmap1 Tmap1.nv = nverts; // Initialize number of vertices #if SC2000K last_y = f2i(vertbuf[0]->p3_sy); flat_flag = 1; // Says so far, this texture map exists all on one scan line #endif // div_numerator = DivNum; //f1_0*3; for (i=0; i<nverts; i++) { g3ds_vertex *tvp = &Tmap1.verts[i]; g3s_point *vp = vertbuf[i]; tvp->x2d = vp->p3_sx; tvp->y2d = vp->p3_sy; #if SC2000K // If y coordinates are not the same (in integer portion), then this texture map is not all on one scan line if (f2i(tvp->y2d) != last_y) flat_flag = 0; // If everything is flat so far, set minimum x and y for rendering a scanline if (flat_flag) { if (tvp->x2d < min_x) min_x = tvp->x2d; if (tvp->x2d > max_x) max_x = tvp->x2d; } #endif // Check for overflow on fixdiv. Will overflow on vp->z <= something small. Allow only as low as 256. if (vp->z < 256) { vp->z = 256; // Int3(); // we would overflow if we divided! } tvp->z = fixdiv(F1_0*12, vp->z); tvp->u = vp->p3_u << 6; //* bp->bm_w; tvp->v = vp->p3_v << 6; //* bp->bm_h; Assert(Lighting_on < 3); if (Lighting_on) tvp->l = vp->p3_l * NUM_LIGHTING_LEVELS; } #if SC2000K // Render a horizontal line instead of a texture map if flat_flag still set (all vertices on one scanline). if (SC2000 && flat_flag) { fix y,cvw; Int3(); y = Tmap1.verts[0].y2d; cvw = i2f(grd_curcanv->cv_bitmap.bm_w-1); if (y<0 || y>i2f(grd_curcanv->cv_bitmap.bm_h-1)) { Lighting_on = lighting_on_save; return; } //if (min_x < 0) min_x = 0; //if (max_x > cvw) max_x = cvw; gr_setcolor(*(bp->bm_data+32*32+32)); // Read center pixel of 64x64 bitmap, use as line color. gr_line(min_x, Tmap1.verts[0].y2d, max_x, Tmap1.verts[0].y2d); Lighting_on = lighting_on_save; return; } #endif Lighting_enabled = Lighting_on; // Now, call my texture mapper. if (Lighting_on) { switch (Interpolation_method) { // 0 = choose, 1 = linear, 2 = /8 perspective, 3 = full perspective case 0: // choose best interpolation per2_flag = 1; if (Current_seg_depth > Max_perspective_depth) ntexture_map_lighted_linear(bp, &Tmap1); else ntexture_map_lighted(bp, &Tmap1); break; case 1: // linear interpolation per2_flag = 1; ntexture_map_lighted_linear(bp, &Tmap1); break; case 2: // perspective every 8th pixel interpolation per2_flag = 1; ntexture_map_lighted(bp, &Tmap1); break; case 3: // perspective every pixel interpolation per2_flag = 0; // this hack means do divide every pixel ntexture_map_lighted(bp, &Tmap1); break; default: Assert(0); // Illegal value for Interpolation_method, must be 0,1,2,3 } } else { switch (Interpolation_method) { // 0 = choose, 1 = linear, 2 = /8 perspective, 3 = full perspective case 0: // choose best interpolation per2_flag = 1; if (Current_seg_depth > Max_perspective_depth) ntexture_map_lighted_linear(bp, &Tmap1); else ntexture_map_lighted(bp, &Tmap1); break; case 1: // linear interpolation per2_flag = 1; ntexture_map_lighted_linear(bp, &Tmap1); break; case 2: // perspective every 8th pixel interpolation per2_flag = 1; ntexture_map_lighted(bp, &Tmap1); break; case 3: // perspective every pixel interpolation per2_flag = 0; // this hack means do divide every pixel ntexture_map_lighted(bp, &Tmap1); break; default: Assert(0); // Illegal value for Interpolation_method, must be 0,1,2,3 } } Lighting_on = lighting_on_save; }