Example #1
0
void plPassMtl::SetupGfxMultiMaps(TimeValue t, Material *mtl, MtlMakerCallback &cb)
{
#if 0
    if (texHandleValid.InInterval(t)) {
        mtl->texture.SetCount(numTexHandlesUsed);
        for (int i=0; i<numTexHandlesUsed; i++) {
            if (texHandle[i]) {
                mtl->texture[i].textHandle = texHandle[i]->GetHandle();
                Texmap *tx = (*maps)[useSubForTex[i]].map;
                cb.GetGfxTexInfoFromTexmap(t, mtl->texture[i], tx );        
                SetTexOps(mtl,i,texOpsType[i]);
                }
            }
        return;
        }
#endif

#if 0   // WTF?!?!?!?
    Texmap *tx[2];
    int diffChan = stdIDToChannel[ ID_DI ];
    int opacChan = stdIDToChannel[ ID_OP ];
    tx[0] = (*maps)[diffChan].IsActive()?(*maps)[diffChan].map:NULL;
    tx[1] = (*maps)[opacChan].IsActive()?(*maps)[opacChan].map:NULL;
#endif

    int nsupport = cb.NumberTexturesSupported();
#if 0
    BITMAPINFO *bmi[NTEXHANDLES];

    int nmaps=0;
    for (int i=0; i<NTEXHANDLES; i++) {
        if (tx[i]) nmaps ++;
        bmi[i] = NULL;
        }
    mtl->texture.SetCount(nmaps);
    if (nmaps==0) 
        return;
    for (i=0; i<nmaps; i++)
        mtl->texture[i].textHandle = NULL;
    texHandleValid.SetInfinite();
    Interval  valid;
    BOOL needDecal = FALSE;
    int ntx = 0;
    int op; 

    int forceW = 0;
    int forceH = 0;
    if (tx[0]) {
        cb.GetGfxTexInfoFromTexmap(t, mtl->texture[0], tx[0]);      
        TextureInfo &ti = mtl->texture[0];
        if (ti.tiling[0]==GW_TEX_NO_TILING||ti.tiling[1]==GW_TEX_NO_TILING)
            needDecal = TRUE;
        op = needDecal?TXOP_ALPHABLEND:TXOP_MODULATE;
        bmi[0] = tx[0]->GetVPDisplayDIB(t,cb,valid,FALSE); 
        if (bmi[0]) {
            texHandleValid &= valid;
            useSubForTex[0] = diffChan;
            ntx = 1;
            forceW = bmi[0]->bmiHeader.biWidth;
            forceH = bmi[0]->bmiHeader.biHeight;
            }
        }
    if (tx[1]) {
        cb.GetGfxTexInfoFromTexmap(t, mtl->texture[ntx], tx[1]);        
        if (nsupport>ntx) {
            bmi[1] = tx[1]->GetVPDisplayDIB(t,cb,valid,TRUE); 
            if (bmi[1]) {
                texHandleValid &= valid;
                StuffAlpha(bmi[1], (*maps)[opacChan].amount, GetOpacity(t),ntx?whiteCol:pShader->GetDiffuseClr(t));
                texHandle[ntx] = cb.MakeHandle(bmi[1]); 
                bmi[1] = NULL; 
                mtl->texture[ntx].textHandle = texHandle[ntx]->GetHandle();
                SetTexOps(mtl,ntx,TXOP_OPACITY);
                useSubForTex[ntx] = opacChan;
                ntx++;
                }
            }
        else {
            if (!needDecal) {
                TextureInfo ti;
//              if (SameUV(mtl->texture[0],mtl->texture[1])) {
                    // Not really correct to combine channels for different UV's but what the heck.
                    bmi[1] = tx[1]->GetVPDisplayDIB(t,cb,valid,TRUE, forceW, forceH); 
                    if (bmi[1]) {
                        texHandleValid &= valid;
                        StuffAlphaInto(bmi[1], bmi[0], (*maps)[opacChan].amount, GetOpacity(t));
                        op = TXOP_OPACITY;
                        free(bmi[1]);
                        bmi[1] = NULL;
                        }
//                  }
                }
            }
        }
    if (bmi[0]) {
        texHandle[0] = cb.MakeHandle(bmi[0]); 
        bmi[0] = NULL; 
        mtl->texture[0].textHandle = texHandle[0]->GetHandle();
        SetTexOps(mtl,0,op);
        }
    mtl->texture.SetCount(ntx);
    numTexHandlesUsed = ntx;
#endif
}
Example #2
0
void Composite::SetupGfxMultiMaps(TimeValue t, Material *mtl, MtlMakerCallback &cb)
{
	Interval valid;
	Texmap *sub[MAXTEXHANDLES];
	int texOp;

	IHardwareMaterial *pIHWMat = (IHardwareMaterial *)GetProperty(PROPID_HARDWARE_MATERIAL);
	if (pIHWMat) {
		// This is only true if Direct3D is in use
		if (texHandleValid.InInterval(t)) {
			pIHWMat->SetNumTexStages(numTexHandlesUsed);
			int nt = numTexHandlesUsed;
			if (numTexHandlesUsed == 1) {
				texOp = TX_MODULATE;
			}
			else {
				texOp = TX_ALPHABLEND;
			}
			for (int i = 0; i < nt; i++) {
				if (texHandle[i]) {
					pIHWMat->SetTexture(i, texHandle[i]->GetHandle());
					// Kludge to pass in the TextureStage number
					mtl->texture[0].useTex = i;
					cb.GetGfxTexInfoFromTexmap(t, mtl->texture[0], subTex[useSubForTex[i]]); 		
					SetHWTexOps(pIHWMat, i, texOp);
				}
			}
			return;
		}
		else {
			DiscardTexHandles();
		}

		int forceW = 0;
		int forceH = 0;

		int nsupport = cb.NumberTexturesSupported();

		nsupport = (nsupport > MAXTEXHANDLES) ? MAXTEXHANDLES : nsupport;

		numTexHandlesUsed = 0;

		for (int i = 0; i < MAXTEXHANDLES; i++) {
			texHandle[i] = NULL;
			sub[i] = NULL;
		}

		int nmaps = 0;
		for (i = 0; i < subTex.Count(); i++) {
			if (mapOn[i]) {
				if (subTex[i]) {
					sub[nmaps] = subTex[i];
					useSubForTex[nmaps] = i;
					if (++nmaps >= nsupport) {
						break;
					}
				}
			}
		}

		pIHWMat->SetNumTexStages(nmaps);
		for (i = 0; i < nmaps; i++) {
			pIHWMat->SetTexture(i, (DWORD_PTR)NULL);
		}

		numTexHandlesUsed  = nmaps;

		texHandleValid.SetInfinite();
		
		if (numTexHandlesUsed == 1) {
			texOp = TX_MODULATE;
		}
		else {
			texOp = TX_ALPHABLEND;
		}
		for (i = 0; i < numTexHandlesUsed; i++) {
			// Kludge to pass in the TextureStage number
			mtl->texture[0].useTex = i;
			cb.GetGfxTexInfoFromTexmap(t, mtl->texture[0], sub[i]);
			BITMAPINFO *bmi = sub[i]->GetVPDisplayDIB(t, cb, valid, FALSE, 0, 0);
			texHandle[i] = cb.MakeHandle(bmi);
			pIHWMat->SetTexture(i, texHandle[i]->GetHandle());
			SetHWTexOps(pIHWMat, i, texOp);
		}
	}
	else {
		if (texHandleValid.InInterval(t)) {
			mtl->texture.SetCount(numTexHandlesUsed);
			int nt = numTexHandlesUsed;
			for (int i=0; i<nt; i++) {
				if (texHandle[i]) {
					mtl->texture[i].textHandle = texHandle[i]->GetHandle();
					cb.GetGfxTexInfoFromTexmap(t, mtl->texture[i], subTex[useSubForTex[i]] ); 		
					SetTexOps(&mtl->texture[i],numTexHandlesUsed==1?TX_MODULATE:TX_ALPHABLEND);
				}
			}
			return;
		}
		else {
			DiscardTexHandles();
		}

		int forceW = 0;
		int forceH = 0;

		int nsupport = cb.NumberTexturesSupported();

		nsupport = (nsupport > MAXTEXHANDLES) ? MAXTEXHANDLES : nsupport;

		numTexHandlesUsed = 0;

		for (int i=0; i<MAXTEXHANDLES; i++) {
			texHandle[i] = NULL;
			sub[i]=NULL;
			}

		
		int nmaps = 0;
		for (i=0; i<subTex.Count(); i++) {
			if (mapOn[i]) {
				if (subTex[i]) {
					sub[nmaps] = subTex[i];
					useSubForTex[nmaps] = i;
					if (++nmaps>=nsupport)
						break;
					}
				}
			}

		mtl->texture.SetCount(nmaps);
		for (i=0; i<nmaps; i++) {
			mtl->texture[i].textHandle = NULL;
			}

		numTexHandlesUsed  = nmaps;

		texHandleValid.SetInfinite();
		
		for (i=0; i<nmaps; i++) {
			cb.GetGfxTexInfoFromTexmap(t, mtl->texture[i], sub[i] ); 		
			BITMAPINFO *bmi = sub[i]->GetVPDisplayDIB(t,cb,valid,FALSE,0,0); 
			texHandle[i] = cb.MakeHandle(bmi); 
			mtl->texture[i].textHandle = texHandle[i]->GetHandle();
			SetTexOps(&mtl->texture[i],nmaps==1?TX_MODULATE:TX_ALPHABLEND);
			}
		mtl->texture.SetCount(nmaps);
	}
}