1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113 |
- //===========================================================================//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- #if !defined(MLR_MLRCLIPTRICK_HPP)
- #include <MLR\MLRClipTrick.hpp>
- #endif
- extern DWORD gEnableTextureSort, gShowClippedPolys, gEnableDetailTexture;
- extern unsigned short *indexOffset; // [MidLevelRenderer::Max_Number_Vertices_Per_Mesh]
- #define HUNT_CLIP_ERROR 0
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- CLASSNAME::TransformNoClip(Matrix4D *mat, GOSVertexPool *vt, bool db)
- {
- Check_Object(this);
- Check_Object(vt);
- Verify(index.GetLength() > 0);
- Start_Timer(Transform_Time);
- // unsigned short stride;
- int stride;
- bool textureAnimation = false;
- Scalar deltaU=0.0f, deltaV=0.0f;
-
- if(state.GetTextureHandle())
- {
- MLRTexture *texture = (*MLRTexturePool::Instance)[state.GetTextureHandle()];
- Check_Object(texture);
- textureAnimation = texture->GetAnimateTexture();
- if(textureAnimation)
- {
- Stuff::AffineMatrix4D &textureMatrix = texture->GetTextureMatrix();
- deltaU = textureMatrix(3, 0);
- deltaV = textureMatrix(3, 1);
- }
- }
- int i, j;
- #ifdef I_SAY_YES_TO_TERRAIN
- Scalar terrainUV[2];
- #endif // I_SAY_YES_TO_TERRAIN
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- int m;
- gos_PushCurrentHeap(StaticHeap);
- int tex2count[Limits::Max_Number_Of_Multitextures];
- gos_PopCurrentHeap();
- for(m=0;m<currentNrOfPasses;m++)
- {
- tex2count[m] = 0;
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- int numVertices = GetNumVertices();
- gos_vertices = vt->GetActualVertexPool(db);
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- int tex2count = 0;
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_DETAIL_TEXTURES
- Scalar detailTexCoords[2];
- #endif // I_SAY_YES_TO_DETAIL_TEXTURES
- #if defined(I_SAY_YES_TO_DUAL_TEXTURES) || defined(I_SAY_YES_TO_DETAIL_TEXTURES)
- gos_vertices2uv = vt->GetActualVertexPool2UV(db);
- #endif
- numGOSVertices = 0;
- Verify(index.GetLength() > 0);
- Verify(coords.GetLength() == visibleIndexedVertices.GetLength());
- if(visibleIndexedVerticesKey == false)
- {
- FindVisibleVertices();
- }
- #ifdef _ARMOR
- memset(indexOffset, 0xff, Limits::Max_Number_Vertices_Per_Mesh*sizeof(unsigned short));
- #endif // _ARMOR
- for(j=0,stride=0;j<numVertices;j++)
- {
- if(visibleIndexedVertices[j] == 0)
- {
- stride++;
- }
- else
- {
- #ifdef LAB_ONLY
- Set_Statistic(TransformedVertices, TransformedVertices+1);
- if(db==false)
- {
- Verify (vt->GetLast() + numGOSVertices < Limits::Max_Number_Vertices_Per_Frame);
- }
- else
- {
- Verify (numGOSVertices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- #endif // LAB_ONLY
- *(int *)(&indexOffset[j]) = (j - stride);
- #ifdef I_SAY_YES_TO_TERRAIN
- terrainUV[0] = borderPixelFun + (coords[j].x - minX)*xUVFac;
- terrainUV[1] = borderPixelFun + (coords[j].z - minZ)*zUVFac;
- #endif // I_SAY_YES_TO_TERRAIN
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- if(MLRState::GetMultitextureLightMap() == true && state.GetMultiTextureMode()!=MLRState::MultiTextureOffMode)
- {
- gos_vertices2uv[numGOSVertices].GOSTransformNoClip(
- coords[j],
- *mat,
- &texCoords[j][0],
- &texCoords[numVertices + j][0]
- #if FOG_HACK
- ,state.GetFogMode()
- #endif // FOG_HACK
- );
- #ifdef I_SAY_YES_TO_COLOR
- #if COLOR_AS_DWORD
- gos_vertices2uv[numGOSVertices].argb = (*actualColors)[j];
- #else // COLOR_AS_DWORD
- gos_vertices2uv[numGOSVertices].argb = GOSCopyColor(&(*actualColors)[j]);
- #endif // COLOR_AS_DWORD
- #else // I_SAY_YES_TO_COLOR
- gos_vertices2uv[numGOSVertices].argb = 0xffffffff;
- #endif // I_SAY_YES_TO_COLOR
- }
- else
- {
- gos_vertices[numGOSVertices].GOSTransformNoClip(
- coords[j],
- *mat,
- &texCoords[j][0]
- #if FOG_HACK
- ,state.GetFogMode()
- #endif // FOG_HACK
- );
- (*texCoords2)[tex2count++] = texCoords[numVertices + j];
-
- }
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_DETAIL_TEXTURES
- if( MLRState::GetMultitextureLightMap() == true &&
- state.GetMultiTextureMode()!=MLRState::MultiTextureOffMode &&
- gEnableDetailTexture==1
- )
- {
- #ifdef I_SAY_YES_TO_TERRAIN2
- detailTexCoords[0] = texCoords[j][0]*xScale;
- detailTexCoords[1] = texCoords[j][1]*yScale;
- #else
- detailTexCoords[0] = texCoords[j][0]*xScale + xOffset;
- detailTexCoords[1] = texCoords[j][1]*yScale + yOffset;
- #endif
- Verify( MLRState::GetHasMaxUVs() ? (detailTexCoords[0]>=-MLRState::GetMaxUV() && detailTexCoords[0]<=MLRState::GetMaxUV()) : 1);
- Verify( MLRState::GetHasMaxUVs() ? (detailTexCoords[1]>=-MLRState::GetMaxUV() && detailTexCoords[1]<=MLRState::GetMaxUV()) : 1);
- gos_vertices2uv[numGOSVertices].GOSTransformNoClip(
- coords[j],
- *mat,
- &texCoords[j][0],
- &detailTexCoords[0]
- #if FOG_HACK
- ,state.GetFogMode()
- #endif // FOG_HACK
- );
- #ifdef I_SAY_YES_TO_COLOR
- #if COLOR_AS_DWORD
- gos_vertices2uv[numGOSVertices].argb = (*actualColors)[j];
- #else // COLOR_AS_DWORD
- gos_vertices2uv[numGOSVertices].argb = GOSCopyColor(&(*actualColors)[j]);
- #endif // COLOR_AS_DWORD
- #else // I_SAY_YES_TO_COLOR
- gos_vertices2uv[numGOSVertices].argb = 0xffffffff;
- #endif // I_SAY_YES_TO_COLOR
- if(gos_vertices[j].rhw < fadeDetailEnd)
- {
- gos_vertices[j].argb &= 0x00ffffff;
- }
- else
- {
- if(gos_vertices[j].rhw<fadeDetailStart)
- {
- gos_vertices[j].argb &= ((Stuff::Truncate_Float_To_Word((gos_vertices[j].rhw - fadeDetailEnd)*fadeMultiplicator)) << 24) | 0x00ffffff;
- }
- }
- }
- else
- #endif // I_SAY_YES_TO_DETAIL_TEXTURES
- {
- gos_vertices[numGOSVertices].GOSTransformNoClip(
- coords[j],
- *mat,
- #ifdef I_SAY_YES_TO_TERRAIN
- terrainUV
- #else // I_SAY_YES_TO_TERRAIN
- &texCoords[j][0]
- #endif // I_SAY_YES_TO_TERRAIN
- #if FOG_HACK
- , state.GetFogMode()
- #endif // FOG_HACK
- );
- #ifdef I_SAY_YES_TO_COLOR
- #if COLOR_AS_DWORD
- gos_vertices[numGOSVertices].argb = (*actualColors)[j];
- #else // COLOR_AS_DWORD
- gos_vertices[numGOSVertices].argb = GOSCopyColor(&(*actualColors)[j]);
- #endif // COLOR_AS_DWORD
- #else // I_SAY_YES_TO_COLOR
- gos_vertices[numGOSVertices].argb = 0xffffffff;
- #endif // I_SAY_YES_TO_COLOR
- }
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- if(textureAnimation)
- {
- gos_vertices[numGOSVertices].u += deltaU;
- gos_vertices[numGOSVertices].v += deltaV;
- }
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=1;m<currentNrOfPasses;m++)
- {
- extraMultiTexCoords[m][tex2count[m]++] = multiTexCoordsPointers[m][j];
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- numGOSVertices++;
- }
- }
- #ifdef LAB_ONLY
- Set_Statistic(NonClippedVertices, NonClippedVertices+numGOSVertices);
- #endif // LAB_ONLY
- Check_Object(vt);
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- if(MLRState::GetMultitextureLightMap() == false || state.GetMultiTextureMode()==MLRState::MultiTextureOffMode)
- {
- Verify (tex2count == numGOSVertices);
- if(db==false)
- {
- Verify (vt->GetLast() + 2*numGOSVertices < vt->GetLength());
- }
- else
- {
- Verify (2*numGOSVertices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- if(state2.GetTextureHandle())
- {
- MLRTexture *texture = (*MLRTexturePool::Instance)[state.GetTextureHandle()];
- Verify(texture);
- textureAnimation = texture->GetAnimateTexture();
- if(textureAnimation)
- {
- Stuff::AffineMatrix4D &textureMatrix = texture->GetTextureMatrix();
- deltaU = textureMatrix(3, 0);
- deltaV = textureMatrix(3, 1);
- }
- }
- memcpy(gos_vertices + numGOSVertices, gos_vertices, numGOSVertices * sizeof(GOSVertex));
- if(textureAnimation)
- {
- for(i=0,j=numGOSVertices;i<numGOSVertices;i++,j++)
- {
- gos_vertices[j].u = (*texCoords2)[i][0] + deltaU;
- gos_vertices[j].v = (*texCoords2)[i][1] + deltaV;
- }
- }
- else
- {
- for(i=0,j=numGOSVertices;i<numGOSVertices;i++,j++)
- {
- gos_vertices[j].u = (*texCoords2)[i][0];
- gos_vertices[j].v = (*texCoords2)[i][1];
- }
- }
- if(db==false)
- {
- vt->Increase(2*numGOSVertices);
- }
- }
- else
- {
- if(db==false)
- {
- vt->Increase2UV(numGOSVertices);
- }
- }
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_DETAIL_TEXTURES
- if( gEnableDetailTexture==1)
- {
- if(MLRState::GetMultitextureLightMap() == false || state.GetMultiTextureMode()==MLRState::MultiTextureOffMode )
- {
- if(db==false)
- {
- Verify (vt->GetLast() + 2*numGOSVertices < vt->GetLength());
- }
- else
- {
- Verify (2*numGOSVertices < 2*Limits::Max_Number_Vertices_Per_Mesh );
- }
- memcpy(gos_vertices + numGOSVertices, gos_vertices, numGOSVertices * sizeof(GOSVertex));
- stride = 0;
- for(i=0,j=numGOSVertices;i<numGOSVertices;i++,j++)
- {
- #ifdef I_SAY_YES_TO_TERRAIN2
- gos_vertices[j].u = gos_vertices[i].u*xScale;
- gos_vertices[j].v = gos_vertices[i].v*yScale;
- #else
- gos_vertices[j].u = gos_vertices[i].u*xScale + xOffset;
- gos_vertices[j].v = gos_vertices[i].v*yScale + yOffset;
- #endif
- Verify( MLRState::GetHasMaxUVs() ? (gos_vertices[j].u>=-MLRState::GetMaxUV() && gos_vertices[j].u<=MLRState::GetMaxUV()) : 1);
- Verify( MLRState::GetHasMaxUVs() ? (gos_vertices[j].v>=-MLRState::GetMaxUV() && gos_vertices[j].v<=MLRState::GetMaxUV()) : 1);
- if(gos_vertices[j].rhw < fadeDetailEnd)
- {
- gos_vertices[j].argb &= 0x00ffffff;
- }
- else
- {
- stride++;
- if(gos_vertices[j].rhw<fadeDetailStart)
- {
- gos_vertices[j].argb &= ((Stuff::Truncate_Float_To_Word((gos_vertices[j].rhw - fadeDetailEnd)*fadeMultiplicator)) << 24) | 0x00ffffff;
- }
- }
- }
- if(stride==0)
- {
- detTextureVisible=false;
- }
- else
- {
- detTextureVisible=true;
- }
- if(db==false)
- {
- vt->Increase(2*numGOSVertices);
- }
- }
- else
- {
- if(db==false)
- {
- vt->Increase2UV(numGOSVertices);
- }
- }
- }
- else
- {
- if(db==false)
- {
- vt->Increase(numGOSVertices);
- }
- }
- #else // I_SAY_YES_TO_DETAIL_TEXTURES
- if(db==false)
- {
- vt->Increase(numGOSVertices);
- }
- #endif // I_SAY_YES_TO_DETAIL_TEXTURES
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=1;m<currentNrOfPasses;m++)
- {
- Verify (tex2count[m] == numGOSVertices);
- if(db==false)
- {
- Verify (vt->GetLast() + numGOSVertices < vt->GetLength());
- }
- else
- {
- Verify (numGOSVertices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- memcpy(gos_vertices + numGOSVertices, gos_vertices, numGOSVertices * sizeof(GOSVertex));
- for(i=0,j=numGOSVertices;i<numGOSVertices;i++,j++)
- {
- gos_vertices[j].u = extraMultiTexCoords[m][i][0];
- gos_vertices[j].v = extraMultiTexCoords[m][i][1];
- }
- if(db==false)
- {
- vt->Increase(numGOSVertices);
- }
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- gos_indices = vt->GetActualIndexPool(db);
- numGOSIndices = 0;
- int ngi = 0;
- for(i=0,j=0;i<numOfTriangles;j+=3,++i)
- {
- if(testList[i] == 0)
- {
- continue;
- }
- if(db==false)
- {
- Verify((vt->GetLastIndex() + 3 + numGOSIndices) < vt->GetLength());
- }
- else
- {
- Verify(3 + numGOSIndices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- Verify(indexOffset[index[j]] < numGOSVertices);
- gos_indices[ngi++] = indexOffset[index[j]];
- Verify(indexOffset[index[j+2]] < numGOSVertices);
- gos_indices[ngi++] = indexOffset[index[j+2]];
- Verify(indexOffset[index[j+1]] < numGOSVertices);
- gos_indices[ngi++] = indexOffset[index[j+1]];
- }
- numGOSIndices = (unsigned short)ngi;
- Check_Object(vt);
- if(db==false)
- {
- vt->IncreaseIndex(numGOSIndices);
- }
- visible = numGOSVertices ? (unsigned char)1 : (unsigned char)0;
- Stop_Timer(Transform_Time);
- }
- static MLRClippingState theAnd, theOr, theTest;
- // extern void _stdcall CheckVertices( gos_VERTEX* pVertexArray, DWORD NumberVertices, bool PointsLines );
- // extern void _stdcall CheckVertices1( gos_VERTEX_2UV* pVertexArray, DWORD NumberVertices );
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // Now it gets serious
- int
- CLASSNAME::TransformAndClip(Matrix4D *mat, MLRClippingState clippingFlags, GOSVertexPool *vt, bool db)
- {
- Check_Object(this);
- Start_Timer(Transform_Time);
- Verify(numOfTriangles == testList.GetLength());
- Verify(clippingFlags.GetClippingState() != 0);
- //
- //--------------------------------------
- // See if we don't have to draw anything
- //--------------------------------------
- //
- if(numOfTriangles <= 0)
- {
- visible = 0;
- Stop_Timer(Transform_Time);
- return visible;
- }
- Verify(index.GetLength() > 0);
- unsigned short l;
- int i, j, k, ret = 0;
- int len = coords.GetLength();
- if(visibleIndexedVerticesKey == false)
- {
- FindVisibleVertices();
- }
- Stuff::Vector4D *v4d = transformedCoords->GetData();
- Stuff::Point3D *p3d = coords.GetData();
- int *cs = (int *)clipPerVertex->GetData();
- unsigned char *viv = visibleIndexedVertices.GetData();
- for(i=0;i<len;i++,p3d++,v4d++,cs++,viv++)
- {
- if(*viv == 0)
- {
- continue;
- }
- *viv = 0;
- v4d->MultiplySetClip(*p3d, *mat, cs);
- #ifdef LAB_ONLY
- Set_Statistic(TransformedVertices, TransformedVertices+1);
- #endif // LAB_ONLY
- //
- //--------------------------------------------------------
- // I claims all vertices are in. lets check it. who knows
- //--------------------------------------------------------
- //
- #ifdef LAB_ONLY
- if( (*cs)==0)
- {
- #if defined(_ARMOR)
- if(ArmorLevel > 3)
- {
- //
- //--------------------------------------------------------
- // I claims all vertices are in. lets check it. who knows
- //--------------------------------------------------------
- //
- Verify(v4d->x >= 0.0f && v4d->x <= v4d->w );
- Verify(v4d->y >= 0.0f && v4d->y <= v4d->w );
- Verify(v4d->z >= 0.0f && v4d->z <= v4d->w );
- }
- #endif // _ARMOR
- Set_Statistic(NonClippedVertices, NonClippedVertices+1);
- }
- else
- {
- Set_Statistic(ClippedVertices, ClippedVertices+1);
- }
- #endif // LAB_ONLY
- }
- Stop_Timer(Transform_Time);
- Start_Timer(Clipping_Time);
- int mask, k0, k1, ct=0;
- Scalar a=0.0f;
- bool textureAnimation = false;
- Scalar deltaU=0.0f, deltaV=0.0f;
-
- if(state.GetTextureHandle())
- {
- MLRTexture *texture = (*MLRTexturePool::Instance)[state.GetTextureHandle()];
- Check_Object(texture);
- textureAnimation = texture->GetAnimateTexture();
- if(textureAnimation)
- {
- Stuff::AffineMatrix4D &textureMatrix = texture->GetTextureMatrix();
- deltaU = textureMatrix(3, 0);
- deltaV = textureMatrix(3, 1);
- }
- }
- #if defined(I_SAY_YES_TO_DUAL_TEXTURES) || defined(I_SAY_YES_TO_DETAIL_TEXTURES)
- gos_vertices2uv = vt->GetActualVertexPool2UV(db);
- bool textureAnimation2 = false;
- Scalar deltaU2=0.0f, deltaV2=0.0f;
- if(state2.GetTextureHandle())
- {
- MLRTexture *texture = (*MLRTexturePool::Instance)[state2.GetTextureHandle()];
- Verify(texture);
- textureAnimation2 = texture->GetAnimateTexture();
- if(textureAnimation2)
- {
- Stuff::AffineMatrix4D &textureMatrix = texture->GetTextureMatrix();
- deltaU2 = textureMatrix(3, 0);
- deltaV2 = textureMatrix(3, 1);
- }
- }
- #endif // I_SAY_YES_TO_DUAL_TEXTURES || I_SAY_YES_TO_DETAIL_TEXTURES
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- int tex2count = 0;
- int numVertices = GetNumVertices();
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- int m;
- gos_PushCurrentHeap(StaticHeap);
- int tex2count[Limits::Max_Number_Of_Multitextures];
- gos_PopCurrentHeap();
- for(m=0;m<currentNrOfPasses;m++)
- {
- tex2count[m] = 0;
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- int myNumberUsedClipVertex, myNumberUsedClipIndex, myNumberUsedClipLength;
- myNumberUsedClipVertex = 0;
- myNumberUsedClipIndex = 0;
- myNumberUsedClipLength = 0;
- Verify(index.GetLength() > 0);
-
- //
- //------------------------
- // Handle the indexed case
- //------------------------
- //
- //
- //-----------------------------------------------------------------
- // Step through each polygon, making sure that we don't try to clip
- // backfaced polygons
- //-----------------------------------------------------------------
- //
- cs = (int *)clipPerVertex->GetData();
- int index0, index1, index2;
- for(i=0,j=0;i<numOfTriangles;j+=3,++i)
- {
- // if(testList[i] == 0)
- // {
- // continue;
- // }
- index0 = index[j];
- index1 = index[j+1];
- index2 = index[j+2];
- //
- //---------------------------------------------------------------
- // Test each vertex of the polygon against the allowed clipping
- // planes, and accumulate status for which planes always clip and
- // which planes clipped at least once
- //---------------------------------------------------------------
- //
- theAnd = cs[index0];
- theOr = theAnd;
- theAnd &= (cs[index1] & cs[index2]);
- theOr |= (cs[index1] | cs[index2]);
- //
- //-------------------------------------------------------------------
- // If any bit is set for all vertices, then the polygon is completely
- // outside the viewing space and we don't have to draw it. On the
- // other hand, if no bits at all were ever set, we can do a trivial
- // accept of the polygon
- //-------------------------------------------------------------------
- //
- theAnd = theOr = 0; //ASSUME NO CLIPPING NEEDED FOR MC2. Its just not done here!
- if (theAnd != 0)
- {
- testList[i] = 0;
- #ifdef LAB_ONLY
- Set_Statistic(PolysClippedButOutside, PolysClippedButOutside+1);
- #endif // LAB_ONLY
- }
- else if (theOr == 0)
- {
- ret++;
- visibleIndexedVertices[index0] = 1;
- visibleIndexedVertices[index1] = 1;
- visibleIndexedVertices[index2] = 1;
- #ifdef I_SAY_YES_TO_TERRAIN
- (*clipTexCoords)[index0][0] = borderPixelFun + (coords[index0].x - minX)*xUVFac;
- (*clipTexCoords)[index0][1] = borderPixelFun + (coords[index0].z - minZ)*zUVFac;
- (*clipTexCoords)[index1][0] = borderPixelFun + (coords[index1].x - minX)*xUVFac;
- (*clipTexCoords)[index1][1] = borderPixelFun + (coords[index1].z - minZ)*zUVFac;
- (*clipTexCoords)[index2][0] = borderPixelFun + (coords[index2].x - minX)*xUVFac;
- (*clipTexCoords)[index2][1] = borderPixelFun + (coords[index2].z - minZ)*zUVFac;
- #endif // I_SAY_YES_TO_TERRAIN
-
- #ifdef LAB_ONLY
- Set_Statistic(PolysClippedButInside, PolysClippedButInside+1);
- #endif // LAB_ONLY
- }
- //
- //-----------------------------------------------------------------
- // It is not a trivial case, so we must now do real clipping on the
- // polygon
- //-----------------------------------------------------------------
- //
- else
- {
- unsigned short numberVerticesPerPolygon = 0;
- #ifdef I_SAY_YES_TO_TERRAIN
- (*clipTexCoords)[index0][0] = borderPixelFun + (coords[index0].x - minX)*xUVFac;
- (*clipTexCoords)[index0][1] = borderPixelFun + (coords[index0].z - minZ)*zUVFac;
- (*clipTexCoords)[index1][0] = borderPixelFun + (coords[index1].x - minX)*xUVFac;
- (*clipTexCoords)[index1][1] = borderPixelFun + (coords[index1].z - minZ)*zUVFac;
- (*clipTexCoords)[index2][0] = borderPixelFun + (coords[index2].x - minX)*xUVFac;
- (*clipTexCoords)[index2][1] = borderPixelFun + (coords[index2].z - minZ)*zUVFac;
- #endif // I_SAY_YES_TO_TERRAIN
- //
- //---------------------------------------------------------------
- // Handle the case of a single clipping plane by stepping through
- // the vertices and finding the edge it originates
- //---------------------------------------------------------------
- //
- bool firstIsIn;
- if (theOr.GetNumberOfSetBits() == 1)
- {
- #ifdef LAB_ONLY
- Set_Statistic(PolysClippedButOnePlane, PolysClippedButOnePlane+1);
- #endif // LAB_ONLY
- for(k=j;k<j+3;k++)
- {
- k0 = index[k];
- k1 = index[(k+1) < j+3 ? k+1 : j];
- //
- //----------------------------------------------------
- // If this vertex is inside the viewing space, copy it
- // directly to the clipping buffer
- //----------------------------------------------------
- //
- int clipped_index =
- myNumberUsedClipVertex + numberVerticesPerPolygon;
- theTest = cs[k0];
- if(theTest == 0)
- {
- firstIsIn = true;
- (*clipExtraCoords)[clipped_index] = (*transformedCoords)[k0];
- #ifdef I_SAY_YES_TO_COLOR
- Verify((*actualColors).GetLength() > 0);
- (*clipExtraColors)[clipped_index] = (*actualColors)[k0];
- #endif // I_SAY_YES_TO_COLOR
- #ifdef I_SAY_YES_TO_TERRAIN
- (*clipExtraTexCoords)[clipped_index] = (*clipTexCoords)[k0];
- #else // I_SAY_YES_TO_TERRAIN
- Verify(texCoords.GetLength() > 0);
- (*clipExtraTexCoords)[clipped_index] = texCoords[k0];
- #endif // I_SAY_YES_TO_TERRAIN
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- (*clipExtraTexCoords2)[clipped_index] = texCoords[k0+numVertices];
- #endif
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=1;m<currentNrOfPasses;m++)
- {
- clipExtraMultiTexCoords[m][clipped_index] = multiTexCoordsPointers[m][k0];
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- numberVerticesPerPolygon++;
- clipped_index++;
- //
- //-------------------------------------------------------
- // We don't need to clip this edge if the next vertex is
- // also in the viewing space, so just move on to the next
- // vertex
- //-------------------------------------------------------
- //
- if(cs[k1] == 0)
- {
- continue;
- }
- }
- //
- //---------------------------------------------------------
- // This vertex is outside the viewing space, so if the next
- // vertex is also outside the viewing space, no clipping is
- // needed and we throw this vertex away. Since only one
- // clipping plane is involved, it must be in the same space
- // as the first vertex
- //---------------------------------------------------------
- //
- else
- {
- firstIsIn = false;
- if(cs[k1] != 0)
- {
- Verify(cs[k1] == cs[k0]);
- continue;
- }
- }
- //
- //--------------------------------------------------
- // We now find the distance along the edge where the
- // clipping plane will intersect
- //--------------------------------------------------
- //
- mask = 1;
- theTest |= cs[k1];
- //
- //-----------------------------------------------------
- // Find the boundary conditions that match our clipping
- // plane
- //-----------------------------------------------------
- //
- for (l=0; l<MLRClippingState::NextBit; l++)
- {
- if(theTest.IsClipped(mask))
- {
- // GetDoubleBC(l, bc0, bc1, transformedCoords[k0], transformedCoords[k1]);
- //
- //-------------------------------------------
- // Find the clipping interval from bc0 to bc1
- //-------------------------------------------
- //
- if(firstIsIn==true)
- {
- a = GetLerpFactor(l, (*transformedCoords)[k0], (*transformedCoords)[k1]);
- }
- else
- {
- a = GetLerpFactor(l, (*transformedCoords)[k1], (*transformedCoords)[k0]);
- }
- Verify(a >= 0.0f && a <= 1.0f);
- ct = l;
- break;
- }
- mask <<= 1;
- }
- //
- //------------------------------
- // Lerp the homogeneous position
- //------------------------------
- //
- if(firstIsIn==true)
- {
- (*clipExtraCoords)[clipped_index].Lerp(
- (*transformedCoords)[k0],
- (*transformedCoords)[k1],
- a
- );
- DoClipTrick((*clipExtraCoords)[clipped_index], ct);
- //
- //----------------------------------------------------------
- // If there are colors, lerp them in screen space for now as
- // most cards do that anyway
- //----------------------------------------------------------
- //
- #ifdef I_SAY_YES_TO_COLOR
- Verify((*actualColors).GetLength() > 0);
- #if COLOR_AS_DWORD
- (*clipExtraColors)[clipped_index] = Color_DWORD_Lerp (
- (*actualColors)[k0],
- (*actualColors)[k1],
- a
- );
- #else // COLOR_AS_DWORD
- (*clipExtraColors)[clipped_index].Lerp(
- (*actualColors)[k0],
- (*actualColors)[k1],
- a
- );
- #endif // COLOR_AS_DWORD
- #endif // I_SAY_YES_TO_COLOR
- //
- //-----------------------------------------------------
- // If there are texture uv's, we need to lerp them in a
- // perspective correct manner
- //-----------------------------------------------------
- //
- #ifdef I_SAY_YES_TO_TERRAIN
- (*clipExtraTexCoords)[clipped_index].Lerp
- (
- (*clipTexCoords)[k0],
- (*clipTexCoords)[k1],
- a
- );
- #else // I_SAY_YES_TO_TERRAIN
- Verify(texCoords.GetLength() > 0);
- (*clipExtraTexCoords)[clipped_index].Lerp
- (
- texCoords[k0],
- texCoords[k1],
- a
- );
- #endif // I_SAY_YES_TO_TERRAIN
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- (*clipExtraTexCoords2)[clipped_index].Lerp
- (
- texCoords[k0+numVertices],
- texCoords[k1+numVertices],
- a
- );
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=1;m<currentNrOfPasses;m++)
- {
- (*clipExtraMultiTexCoords)[m][clipped_index] .Lerp
- (
- multiTexCoordsPointers[m][k0],
- multiTexCoordsPointers[m][k1],
- a
- );
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- }
- else
- {
- (*clipExtraCoords)[clipped_index].Lerp(
- (*transformedCoords)[k1],
- (*transformedCoords)[k0],
- a
- );
- DoClipTrick((*clipExtraCoords)[clipped_index], ct);
- //
- //----------------------------------------------------------
- // If there are colors, lerp them in screen space for now as
- // most cards do that anyway
- //----------------------------------------------------------
- //
- #ifdef I_SAY_YES_TO_COLOR
- Verify((*actualColors).GetLength() > 0);
- #if COLOR_AS_DWORD
- (*clipExtraColors)[clipped_index] = Color_DWORD_Lerp (
- (*actualColors)[k1],
- (*actualColors)[k0],
- a
- );
- #else // COLOR_AS_DWORD
- (*clipExtraColors)[clipped_index].Lerp(
- (*actualColors)[k1],
- (*actualColors)[k0],
- a
- );
- #endif // COLOR_AS_DWORD
- #endif // I_SAY_YES_TO_COLOR
- //
- //-----------------------------------------------------
- // If there are texture uv's, we need to lerp them in a
- // perspective correct manner
- //-----------------------------------------------------
- //
- #ifdef I_SAY_YES_TO_TERRAIN
- (*clipExtraTexCoords)[clipped_index].Lerp
- (
- (*clipTexCoords)[k1],
- (*clipTexCoords)[k0],
- a
- );
- #else // I_SAY_YES_TO_TERRAIN
- Verify(texCoords.GetLength() > 0);
- (*clipExtraTexCoords)[clipped_index].Lerp
- (
- texCoords[k1],
- texCoords[k0],
- a
- );
- #endif // I_SAY_YES_TO_TERRAIN
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- (*clipExtraTexCoords2)[clipped_index].Lerp
- (
- texCoords[k1+numVertices],
- texCoords[k0+numVertices],
- a
- );
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=1;m<currentNrOfPasses;m++)
- {
- (*clipExtraMultiTexCoords)[m][clipped_index] .Lerp
- (
- multiTexCoordsPointers[m][k1],
- multiTexCoordsPointers[m][k0],
- a
- );
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- }
- //
- //--------------------------------
- // Bump the polygon's vertex count
- //--------------------------------
- //
- numberVerticesPerPolygon++;
- }
- (*clipExtraLength)[myNumberUsedClipLength] = numberVerticesPerPolygon;
- #ifdef _ARMOR
- (*clipExtraLength)[myNumberUsedClipLength] &= ~0x8000;
- #endif // _ARMOR
- }
- //
- //---------------------------------------------------------------
- // We have to handle multiple planes. We do this by creating two
- // buffers and we switch between them as we clip plane by plane
- //---------------------------------------------------------------
- //
- else
- {
- #ifdef LAB_ONLY
- Set_Statistic(PolysClippedButGOnePlane, PolysClippedButGOnePlane+1);
- #endif // LAB_ONLY
- ClipData2 srcPolygon, dstPolygon;
- int dstBuffer = 1;
- #ifndef I_SAY_YES_TO_TERRAIN
- Verify(texCoords.GetLength() > 0);
- #endif // I_SAY_YES_TO_TERRAIN
- srcPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
- #ifdef I_SAY_YES_TO_COLOR
- Verify((*actualColors).GetLength() > 0);
- srcPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
- #endif // I_SAY_YES_TO_COLOR
- srcPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
- srcPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
- //
- //----------------------------------------------------------
- // unravel and copy the original data into the source buffer
- //----------------------------------------------------------
- //
- for(k=j,l=0;k<j+3;k++,l++)
- {
- int indexK = index[k];
- srcPolygon.coords[l] = (*transformedCoords)[indexK];
- #ifdef I_SAY_YES_TO_COLOR
- srcPolygon.colors[l] = (*actualColors)[indexK];
- #endif // I_SAY_YES_TO_COLOR
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- srcPolygon.texCoords[2*l] = texCoords[indexK];
- srcPolygon.texCoords[2*l+1] = texCoords[indexK + numVertices];
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=0;m<currentNrOfPasses;m++)
- {
- srcPolygon.texCoords[currentNrOfPasses*l+m] = multiTexCoordsPointers[m][indexK];
- }
- #else // I_SAY_YES_TO_MULTI_TEXTURES
- #ifdef I_SAY_YES_TO_TERRAIN
- srcPolygon.texCoords[l] = (*clipTexCoords)[indexK];
- #else // I_SAY_YES_TO_TERRAIN
- srcPolygon.texCoords[l] = texCoords[indexK];
- #endif // I_SAY_YES_TO_TERRAIN
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- srcPolygon.clipPerVertex[l] = (*clipPerVertex)[indexK];
- }
- srcPolygon.length = l;
- //
- //--------------------------------
- // Point to the destination buffer
- //--------------------------------
- //
- dstBuffer = 0;
- dstPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
- #ifdef I_SAY_YES_TO_COLOR
- dstPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
- #endif // I_SAY_YES_TO_COLOR
- dstPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
- dstPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
- dstPolygon.length = 0;
- //
- //-----------------------------------------------------------
- // Spin through each plane that clipped the primitive and use
- // it to actually clip the primitive
- //-----------------------------------------------------------
- //
- mask = 1;
- MLRClippingState theNewOr(0);
- int loop = 4;
- #if HUNT_CLIP_ERROR
- for(k=0;k<srcPolygon.length;k++)
- {
- DEBUG_STREAM << setiosflags( ios::scientific) << setprecision(20)
- << srcPolygon.coords[k].x << " "
- << srcPolygon.coords[k].y << " "
- << srcPolygon.coords[k].z << " "
- << srcPolygon.coords[k].w << '\n';
- }
- DEBUG_STREAM << "TheOriginalOR: " << hex << theOr.GetClippingState() << dec << '\n';
- #endif // HUNT_CLIP_ERROR
- do
- {
- for(l=0; l<MLRClippingState::NextBit; l++)
- {
- if(theOr.IsClipped(mask))
- {
- //
- //-----------------------------------
- // Clip each vertex against the plane
- //-----------------------------------
- //
- #if HUNT_CLIP_ERROR
- DEBUG_STREAM << l << ": " << '\n';
- #endif // HUNT_CLIP_ERROR
- for(k=0;k<srcPolygon.length;k++)
- {
- k1 = (k+1) < srcPolygon.length ? k+1 : 0;
- theTest = srcPolygon.clipPerVertex[k];
- //
- //----------------------------------------------------
- // If this vertex is inside the viewing space, copy it
- // directly to the clipping buffer
- //----------------------------------------------------
- //
- if(theTest.IsClipped(mask) == 0)
- {
- firstIsIn = true;
- dstPolygon.coords[dstPolygon.length] =
- srcPolygon.coords[k];
- #if HUNT_CLIP_ERROR
- DEBUG_STREAM << k << " goes " << setiosflags( ios::scientific) << setprecision(20)
- << srcPolygon.coords[k].x << " "
- << srcPolygon.coords[k].y << " "
- << srcPolygon.coords[k].z << " "
- << srcPolygon.coords[k].w << '\n';
- #endif // HUNT_CLIP_ERROR
- dstPolygon.clipPerVertex[dstPolygon.length] =
- srcPolygon.clipPerVertex[k];
- #ifdef I_SAY_YES_TO_COLOR
- dstPolygon.colors[dstPolygon.length] =
- srcPolygon.colors[k];
- #endif // I_SAY_YES_TO_COLOR
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- dstPolygon.texCoords[2*dstPolygon.length] =
- srcPolygon.texCoords[2*k];
- dstPolygon.texCoords[2*dstPolygon.length+1] =
- srcPolygon.texCoords[2*k+1];
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=0;m<currentNrOfPasses;m++)
- {
- dstPolygon.texCoords[currentNrOfPasses*dstPolygon.length+m] =
- srcPolygon.texCoords[currentNrOfPasses*k+m];
- }
- #else // I_SAY_YES_TO_MULTI_TEXTURES
- dstPolygon.texCoords[dstPolygon.length] =
- srcPolygon.texCoords[k];
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- dstPolygon.length++;
- //
- //-------------------------------------------------------
- // We don't need to clip this edge if the next vertex is
- // also in the viewing space, so just move on to the next
- // vertex
- //-------------------------------------------------------
- //
- if(srcPolygon.clipPerVertex[k1].IsClipped(mask) == 0)
- {
- continue;
- }
- }
- //
- //---------------------------------------------------------
- // This vertex is outside the viewing space, so if the next
- // vertex is also outside the viewing space, no clipping is
- // needed and we throw this vertex away. Since only one
- // clipping plane is involved, it must be in the same space
- // as the first vertex
- //---------------------------------------------------------
- //
- else
- {
- firstIsIn = false;
- if(srcPolygon.clipPerVertex[k1].IsClipped(mask) != 0)
- {
- Verify(
- srcPolygon.clipPerVertex[k1].IsClipped(mask)
- == srcPolygon.clipPerVertex[k].IsClipped(mask)
- );
- continue;
- }
- }
- //
- //-------------------------------------------
- // Find the clipping interval from bc0 to bc1
- //-------------------------------------------
- //
- if(firstIsIn == true)
- {
- a = GetLerpFactor (l, srcPolygon.coords[k], srcPolygon.coords[k1]);
- Verify(a >= 0.0f && a <= 1.0f);
- //
- //------------------------------
- // Lerp the homogeneous position
- //------------------------------
- //
- dstPolygon.coords[dstPolygon.length].Lerp(
- srcPolygon.coords[k],
- srcPolygon.coords[k1],
- a
- );
- #if HUNT_CLIP_ERROR
- DEBUG_STREAM << "True " << a << " " << k << " " << k1 << " we get " << dstPolygon.length << '\n';
- DEBUG_STREAM << setiosflags( ios::scientific) << setprecision(20)
- << dstPolygon.coords[dstPolygon.length].x << " "
- << dstPolygon.coords[dstPolygon.length].y << " "
- << dstPolygon.coords[dstPolygon.length].z << " "
- << dstPolygon.coords[dstPolygon.length].w << '\n';
- #endif // HUNT_CLIP_ERROR
- DoClipTrick(dstPolygon.coords[dstPolygon.length], l);
- //
- //----------------------------------------------------------
- // If there are colors, lerp them in screen space for now as
- // most cards do that anyway
- //----------------------------------------------------------
- //
- #ifdef I_SAY_YES_TO_COLOR
- #if COLOR_AS_DWORD
- dstPolygon.colors[dstPolygon.length] = Color_DWORD_Lerp(
- srcPolygon.colors[k],
- srcPolygon.colors[k1],
- a
- );
- #else // COLOR_AS_DWORD
- dstPolygon.colors[dstPolygon.length].Lerp(
- srcPolygon.colors[k],
- srcPolygon.colors[k1],
- a
- );
- #endif // COLOR_AS_DWORD
- #endif // I_SAY_YES_TO_COLOR
- //
- //-----------------------------------------------------
- // If there are texture uv's, we need to lerp them in a
- // perspective correct manner
- //-----------------------------------------------------
- //
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- dstPolygon.texCoords[2*dstPolygon.length].Lerp
- (
- srcPolygon.texCoords[2*k],
- srcPolygon.texCoords[2*k1],
- a
- );
- dstPolygon.texCoords[2*dstPolygon.length+1].Lerp
- (
- srcPolygon.texCoords[2*k+1],
- srcPolygon.texCoords[2*k1+1],
- a
- );
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=0;m<currentNrOfPasses;m++)
- {
- dstPolygon.texCoords[currentNrOfPasses*dstPolygon.length+m].Lerp
- (
- srcPolygon.texCoords[currentNrOfPasses*k+m],
- srcPolygon.texCoords[currentNrOfPasses*k1+m],
- a
- );
- }
- #else // I_SAY_YES_TO_MULTI_TEXTURES
- dstPolygon.texCoords[dstPolygon.length].Lerp
- (
- srcPolygon.texCoords[k],
- srcPolygon.texCoords[k1],
- a
- );
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- }
- else
- {
- a = GetLerpFactor (l, srcPolygon.coords[k1], srcPolygon.coords[k]);
- Verify(a >= 0.0f && a <= 1.0f);
- //
- //------------------------------
- // Lerp the homogeneous position
- //------------------------------
- //
- dstPolygon.coords[dstPolygon.length].Lerp(
- srcPolygon.coords[k1],
- srcPolygon.coords[k],
- a
- );
- #if HUNT_CLIP_ERROR
- DEBUG_STREAM << "False " << a << " " << k << " " << k1 << " we get " << dstPolygon.length << '\n';
- DEBUG_STREAM << setiosflags( ios::scientific) << setprecision(20)
- << dstPolygon.coords[dstPolygon.length].x << " "
- << dstPolygon.coords[dstPolygon.length].y << " "
- << dstPolygon.coords[dstPolygon.length].z << " "
- << dstPolygon.coords[dstPolygon.length].w << '\n';
- #endif // HUNT_CLIP_ERROR
- DoClipTrick(dstPolygon.coords[dstPolygon.length], l);
- //
- //----------------------------------------------------------
- // If there are colors, lerp them in screen space for now as
- // most cards do that anyway
- //----------------------------------------------------------
- //
- #ifdef I_SAY_YES_TO_COLOR
- #if COLOR_AS_DWORD
- dstPolygon.colors[dstPolygon.length] = Color_DWORD_Lerp(
- srcPolygon.colors[k1],
- srcPolygon.colors[k],
- a
- );
- #else // COLOR_AS_DWORD
- dstPolygon.colors[dstPolygon.length].Lerp(
- srcPolygon.colors[k1],
- srcPolygon.colors[k],
- a
- );
- #endif // COLOR_AS_DWORD
- #endif // I_SAY_YES_TO_COLOR
- //
- //-----------------------------------------------------
- // If there are texture uv's, we need to lerp them in a
- // perspective correct manner
- //-----------------------------------------------------
- //
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- dstPolygon.texCoords[2*dstPolygon.length].Lerp
- (
- srcPolygon.texCoords[2*k1],
- srcPolygon.texCoords[2*k],
- a
- );
- dstPolygon.texCoords[2*dstPolygon.length+1].Lerp
- (
- srcPolygon.texCoords[2*k1+1],
- srcPolygon.texCoords[2*k+1],
- a
- );
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=0;m<currentNrOfPasses;m++)
- {
- dstPolygon.texCoords[currentNrOfPasses*dstPolygon.length+m].Lerp
- (
- srcPolygon.texCoords[currentNrOfPasses*k1+m],
- srcPolygon.texCoords[currentNrOfPasses*k+m],
- a
- );
- }
- #else // I_SAY_YES_TO_MULTI_TEXTURES
- dstPolygon.texCoords[dstPolygon.length].Lerp
- (
- srcPolygon.texCoords[k1],
- srcPolygon.texCoords[k],
- a
- );
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- }
- //
- //-------------------------------------
- // We have to generate a new clip state
- //-------------------------------------
- //
- dstPolygon.clipPerVertex[dstPolygon.length].Clip4dVertex(&dstPolygon.coords[dstPolygon.length]);
- //
- //----------------------------------
- // Bump the new polygon vertex count
- //----------------------------------
- //
- dstPolygon.length++;
- }
- //
- //-----------------------------------------------
- // Swap source and destination buffer pointers in
- // preparation for the next plane test
- //-----------------------------------------------
- //
- srcPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
- #ifdef I_SAY_YES_TO_COLOR
- srcPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
- #endif // I_SAY_YES_TO_COLOR
- srcPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
- srcPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
- srcPolygon.length = dstPolygon.length;
- dstBuffer = !dstBuffer;
- dstPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
- #ifdef I_SAY_YES_TO_COLOR
- dstPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
- #endif // I_SAY_YES_TO_COLOR
- dstPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
- dstPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
- dstPolygon.length = 0;
- }
- mask = mask << 1;
- }
- theNewOr = 0;
- for(k=0;k<srcPolygon.length;k++)
- {
- theNewOr |= srcPolygon.clipPerVertex[k];
- }
- #if HUNT_CLIP_ERROR
- DEBUG_STREAM << "TheOR: " << hex << theNewOr.GetClippingState() << dec << '\n';
- #endif // HUNT_CLIP_ERROR
- theOr = theNewOr;
- } while (theNewOr != 0 && loop--);
- //
- //--------------------------------------------------
- // could not clip this rare case, just ignore it
- //--------------------------------------------------
- //
- if(theNewOr != 0)
- {
- testList[i] = 0;
- continue;
- }
- //
- //--------------------------------------------------
- // Move the most recent polygon into the clip buffer
- //--------------------------------------------------
- //
- #if HUNT_CLIP_ERROR
- DEBUG_STREAM << "Final: " << srcPolygon.length << '\n';
- #endif // HUNT_CLIP_ERROR
- for(k=0;k<srcPolygon.length;k++)
- {
- int clipped_index = myNumberUsedClipVertex + k;
- #if HUNT_CLIP_ERROR
- DEBUG_STREAM << setiosflags( ios::scientific) << setprecision(20)
- << srcPolygon.coords[k].x << " "
- << srcPolygon.coords[k].y << " "
- << srcPolygon.coords[k].z << " "
- << srcPolygon.coords[k].w << '\n';
- #endif // HUNT_CLIP_ERROR
- (*clipExtraCoords)[clipped_index] = srcPolygon.coords[k];
- #ifdef I_SAY_YES_TO_COLOR
- (*clipExtraColors)[clipped_index] = srcPolygon.colors[k];
- #endif // I_SAY_YES_TO_COLOR
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- (*clipExtraTexCoords)[clipped_index] = srcPolygon.texCoords[2*k];
- (*clipExtraTexCoords2)[clipped_index] = srcPolygon.texCoords[2*k+1];
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=0;m<currentNrOfPasses;m++)
- {
- (*clipExtraMultiTexCoords)[m][clipped_index] = srcPolygon.texCoords[currentNrOfPasses*k+m];
- }
- #else // I_SAY_YES_TO_MULTI_TEXTURES
- (*clipExtraTexCoords)[clipped_index] = srcPolygon.texCoords[k];
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- }
- numberVerticesPerPolygon = srcPolygon.length;
- #if HUNT_CLIP_ERROR
- DEBUG_STREAM << "---" << '\n';
- #endif // HUNT_CLIP_ERROR
-
- (*clipExtraLength)[myNumberUsedClipLength] = numberVerticesPerPolygon;
- #ifdef _ARMOR
- (*clipExtraLength)[myNumberUsedClipLength] |= 0x8000;
- #endif // _ARMOR
- }
- myNumberUsedClipVertex += numberVerticesPerPolygon;
- myNumberUsedClipLength++;
- ret++;
- // clip
- // dont draw the original
- testList[i] = 0;
- }
- }
- Check_Object(vt);
- gos_vertices = vt->GetActualVertexPool(db);
- numGOSVertices = 0;
- gos_indices = vt->GetActualIndexPool(db);
- numGOSIndices = 0;
- k = visibleIndexedVertices.GetLength();
- unsigned short strideIndex;
- for(j=0,strideIndex=0;j<k;j++)
- {
- if(visibleIndexedVertices[j] == 0)
- {
- strideIndex++;
- }
- else
- {
- indexOffset[j] = static_cast<unsigned short>(j-strideIndex);
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- if(MLRState::GetMultitextureLightMap() == true && state.GetMultiTextureMode()!=MLRState::MultiTextureOffMode)
- {
- GOSCopyData(
- &gos_vertices2uv[numGOSVertices],
- transformedCoords->GetData(),
- #ifdef I_SAY_YES_TO_COLOR
- actualColors->GetData(),
- #endif // I_SAY_YES_TO_COLOR
- #ifdef I_SAY_YES_TO_TERRAIN
- clipTexCoords->GetData(),
- #else // I_SAY_YES_TO_TERRAIN
- texCoords.GetData(),
- #endif // I_SAY_YES_TO_TERRAIN
- texCoords.GetData() + numVertices,
- j
- #if FOG_HACK
- , state.GetFogMode()
- #endif // FOG_HACK
- );
- // CheckVertices1( gos_vertices2uv+numGOSVertices, 1 );
- }
- else
- {
- GOSCopyData(
- &gos_vertices[numGOSVertices],
- transformedCoords->GetData(),
- #ifdef I_SAY_YES_TO_COLOR
- actualColors->GetData(),
- #endif // I_SAY_YES_TO_COLOR
- #ifdef I_SAY_YES_TO_TERRAIN
- clipTexCoords->GetData(),
- #else // I_SAY_YES_TO_TERRAIN
- texCoords.GetData(),
- #endif // I_SAY_YES_TO_TERRAIN
- j
- #if FOG_HACK
- , state.GetFogMode()
- #endif // FOG_HACK
- );
- (*texCoords2)[tex2count++] = texCoords[numVertices + j];
- }
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_DETAIL_TEXTURES
- if( MLRState::GetMultitextureLightMap() == true &&
- state.GetMultiTextureMode()!=MLRState::MultiTextureOffMode &&
- gEnableDetailTexture==1
- )
- {
- GOSCopyData(
- &gos_vertices2uv[numGOSVertices],
- transformedCoords->GetData(),
- #ifdef I_SAY_YES_TO_COLOR
- actualColors->GetData(),
- #endif // I_SAY_YES_TO_COLOR
- #ifdef I_SAY_YES_TO_TERRAIN
- clipTexCoords->GetData(),
- #else // I_SAY_YES_TO_TERRAIN
- texCoords.GetData(),
- #endif // I_SAY_YES_TO_TERRAIN
- #ifdef I_SAY_YES_TO_TERRAIN
- clipTexCoords->GetData(),
- #else // I_SAY_YES_TO_TERRAIN
- texCoords.GetData(),
- #endif // I_SAY_YES_TO_TERRAIN
- j
- #if FOG_HACK
- , state.GetFogMode()
- #endif // FOG_HACK
- );
- }
- else
- #endif // I_SAY_YES_TO_DETAIL_TEXTURES
- {
- GOSCopyData(
- &gos_vertices[numGOSVertices],
- transformedCoords->GetData(),
- #ifdef I_SAY_YES_TO_COLOR
- actualColors->GetData(),
- #endif // I_SAY_YES_TO_COLOR
- #ifdef I_SAY_YES_TO_TERRAIN
- clipTexCoords->GetData(),
- #else // I_SAY_YES_TO_TERRAIN
- texCoords.GetData(),
- #endif // I_SAY_YES_TO_TERRAIN
- j
- #if FOG_HACK
- , state.GetFogMode()
- #endif // FOG_HACK
- );
- }
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- if(textureAnimation)
- {
- gos_vertices[numGOSVertices].u += deltaU;
- gos_vertices[numGOSVertices].v += deltaV;
- }
- #ifdef LAB_ONLY
- if(gShowClippedPolys)
- {
- gos_vertices[numGOSVertices].argb = 0xff0000ff;
- gos_vertices[numGOSVertices].u = 0.0f;
- gos_vertices[numGOSVertices].v = 0.0f;
- }
- #endif // LAB_ONLY
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=1;m<currentNrOfPasses;m++)
- {
- extraMultiTexCoords[m][tex2count[m]++] = multiTexCoordsPointers[m][j];
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- numGOSVertices++;
- }
- }
- for(i=0,j=0;i<numOfTriangles;j+=3,++i)
- {
- if(testList[i] == 0)
- {
- continue;
- }
- if(db==false)
- {
- Verify((vt->GetLastIndex() + 3 + numGOSIndices) < vt->GetLength());
- }
- else
- {
- Verify(3 + numGOSIndices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- Verify(indexOffset[index[j]] < numGOSVertices);
- gos_indices[numGOSIndices] = indexOffset[index[j]];
- Verify(indexOffset[index[j+2]] < numGOSVertices);
- gos_indices[numGOSIndices+1] = indexOffset[index[j+2]];
- Verify(indexOffset[index[j+1]] < numGOSVertices);
- gos_indices[numGOSIndices+2] = indexOffset[index[j+1]];
- numGOSIndices += 3;
- }
- unsigned short stride;
- if(myNumberUsedClipLength > 0)
- {
- for(i=0,j=0;i<myNumberUsedClipLength;i++)
- {
- #ifdef _ARMOR
- stride = static_cast<unsigned short>((*clipExtraLength)[i] & 0x7fff);
- #else // _ARMOR
- stride = (*clipExtraLength)[i];
- #endif // _ARMOR
- for(k=1;k<stride-1;k++)
- {
- if(db==false)
- {
- Verify((vt->GetLast() + 3 + numGOSVertices) < vt->GetLength());
- Verify((vt->GetLastIndex() + 3 + numGOSIndices) < vt->GetLength());
- }
- else
- {
- Verify(3 + numGOSVertices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- Verify(3 + numGOSIndices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- if(MLRState::GetMultitextureLightMap() == true && state.GetMultiTextureMode()!=MLRState::MultiTextureOffMode)
- {
- GOSCopyTriangleData(
- &gos_vertices2uv[numGOSVertices],
- clipExtraCoords->GetData(),
- #ifdef I_SAY_YES_TO_COLOR
- clipExtraColors->GetData(),
- #endif // I_SAY_YES_TO_COLOR
- clipExtraTexCoords->GetData(),
- clipExtraTexCoords2->GetData(),
- j, j+k+1, j+k
- #if FOG_HACK
- , state.GetFogMode()
- #endif // FOG_HACK
- );
- // CheckVertices1( gos_vertices2uv+numGOSVertices, 3 );
- }
- else
- {
- GOSCopyTriangleData(
- &gos_vertices[numGOSVertices],
- clipExtraCoords->GetData(),
- #ifdef I_SAY_YES_TO_COLOR
- clipExtraColors->GetData(),
- #endif // I_SAY_YES_TO_COLOR
- clipExtraTexCoords->GetData(),
- j, j+k+1, j+k
- #if FOG_HACK
- , state.GetFogMode()
- #endif // FOG_HACK
- );
- (*texCoords2)[tex2count++] = (*clipExtraTexCoords2)[j];
- (*texCoords2)[tex2count++] = (*clipExtraTexCoords2)[j+k+1];
- (*texCoords2)[tex2count++] = (*clipExtraTexCoords2)[j+k];
- }
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_DETAIL_TEXTURES
- if( MLRState::GetMultitextureLightMap() == true &&
- state.GetMultiTextureMode()!=MLRState::MultiTextureOffMode &&
- gEnableDetailTexture==1
- )
- {
- GOSCopyTriangleData(
- &gos_vertices2uv[numGOSVertices],
- clipExtraCoords->GetData(),
- #ifdef I_SAY_YES_TO_COLOR
- clipExtraColors->GetData(),
- #endif // I_SAY_YES_TO_COLOR
- clipExtraTexCoords->GetData(),
- clipExtraTexCoords->GetData(),
- j, j+k+1, j+k
- #if FOG_HACK
- , state.GetFogMode()
- #endif // FOG_HACK
- );
- }
- else
- #endif // I_SAY_YES_TO_DETAIL_TEXTURES
- {
- GOSCopyTriangleData(
- &gos_vertices[numGOSVertices],
- clipExtraCoords->GetData(),
- #ifdef I_SAY_YES_TO_COLOR
- clipExtraColors->GetData(),
- #endif // I_SAY_YES_TO_COLOR
- clipExtraTexCoords->GetData(),
- j, j+k+1, j+k
- #if FOG_HACK
- , state.GetFogMode()
- #endif // FOG_HACK
- );
- }
- #endif // I_SAY_YES_TO_DUAL_TEXTURES
- if(textureAnimation)
- {
- gos_vertices[numGOSVertices].u += deltaU;
- gos_vertices[numGOSVertices].v += deltaV;
- gos_vertices[numGOSVertices+1].u += deltaU;
- gos_vertices[numGOSVertices+1].v += deltaV;
- gos_vertices[numGOSVertices+2].u += deltaU;
- gos_vertices[numGOSVertices+2].v += deltaV;
- }
- #ifdef LAB_ONLY
- if(gShowClippedPolys)
- {
- if((*clipExtraLength)[i] & 0x8000)
- {
- gos_vertices[numGOSVertices].argb = 0xffff0000;
- gos_vertices[numGOSVertices].u = 0.0f;
- gos_vertices[numGOSVertices].v = 0.0f;
- gos_vertices[numGOSVertices+1].argb = 0xffff0000;
- gos_vertices[numGOSVertices+1].u = 0.0f;
- gos_vertices[numGOSVertices+1].v = 0.0f;
- gos_vertices[numGOSVertices+2].argb = 0xffff0000;
- gos_vertices[numGOSVertices+2].u = 0.0f;
- gos_vertices[numGOSVertices+2].v = 0.0f;
- }
- else
- {
- gos_vertices[numGOSVertices].argb = 0xffff9999;
- gos_vertices[numGOSVertices].u = 0.0f;
- gos_vertices[numGOSVertices].v = 0.0f;
- gos_vertices[numGOSVertices+1].argb = 0xffff9999;
- gos_vertices[numGOSVertices+1].u = 0.0f;
- gos_vertices[numGOSVertices+1].v = 0.0f;
- gos_vertices[numGOSVertices+2].argb = 0xffff9999;
- gos_vertices[numGOSVertices+2].u = 0.0f;
- gos_vertices[numGOSVertices+2].v = 0.0f;
- }
- }
- #endif // LAB_ONLY
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=1;m<currentNrOfPasses;m++)
- {
- extraMultiTexCoords[m][tex2count[m]++] = clipExtraMultiTexCoords[m][j];
- extraMultiTexCoords[m][tex2count[m]++] = clipExtraMultiTexCoords[m][j+k+1];
- extraMultiTexCoords[m][tex2count[m]++] = clipExtraMultiTexCoords[m][j+k];
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- if(db==false)
- {
- Verify((vt->GetLastIndex() + 3 + numGOSIndices) < vt->GetLength());
- }
- else
- {
- Verify(3 + numGOSIndices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- Verify(numGOSIndices%3 == 0);
- gos_indices[numGOSIndices] = numGOSVertices;
- gos_indices[numGOSIndices+1] = (unsigned short)(numGOSVertices + 1);
- gos_indices[numGOSIndices+2] = (unsigned short)(numGOSVertices + 2);
- numGOSVertices += 3;
- numGOSIndices += 3;
- }
- j += stride;
- }
- #if HUNT_CLIP_ERROR
- DEBUG_STREAM << "***" << endl << endl;
- #endif // HUNT_CLIP_ERROR
- }
- #ifdef I_SAY_YES_TO_DUAL_TEXTURES
- if(MLRState::GetMultitextureLightMap() == false || state.GetMultiTextureMode()==MLRState::MultiTextureOffMode)
- {
- Verify (tex2count == numGOSVertices);
- if(db==false)
- {
- Verify (vt->GetLast() + 2*numGOSVertices < vt->GetLength());
- }
- else
- {
- Verify (2*numGOSVertices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- memcpy(gos_vertices + numGOSVertices, gos_vertices, numGOSVertices * sizeof(GOSVertex));
- if(textureAnimation2)
- {
- for(i=0,j=numGOSVertices;i<numGOSVertices;i++,j++)
- {
- gos_vertices[j].u = (*texCoords2)[i][0] + deltaU2;
- gos_vertices[j].v = (*texCoords2)[i][1] + deltaV2;
- }
- }
- else
- {
- for(i=0,j=numGOSVertices;i<numGOSVertices;i++,j++)
- {
- gos_vertices[j].u = (*texCoords2)[i][0];
- gos_vertices[j].v = (*texCoords2)[i][1];
- }
- }
- if(db==false)
- {
- vt->Increase(2*numGOSVertices);
- }
- }
- else
- {
- if(db==false)
- {
- vt->Increase2UV(numGOSVertices);
- }
- }
- #else // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_DETAIL_TEXTURES
- if(gEnableDetailTexture==1)
- {
- if( MLRState::GetMultitextureLightMap() == true &&
- state.GetMultiTextureMode()!=MLRState::MultiTextureOffMode
- )
- {
- for(i=0;i<numGOSVertices;i++)
- {
- #ifdef I_SAY_YES_TO_TERRAIN2
- gos_vertices2uv[i].u2 = gos_vertices2uv[i].u1*xScale;
- gos_vertices2uv[i].v2 = gos_vertices2uv[i].v1*yScale;
- #else // I_SAY_YES_TO_TERRAIN2
- gos_vertices2uv[i].u2 = gos_vertices2uv[i].u1*xScale + xOffset + deltaU2;
- gos_vertices2uv[i].v2 = gos_vertices2uv[i].v1*yScale + yOffset + deltaV2;
- #endif // I_SAY_YES_TO_TERRAIN2
- Verify( MLRState::GetHasMaxUVs() ? (gos_vertices2uv[i].u2>=-MLRState::GetMaxUV() && gos_vertices2uv[i].u2<=MLRState::GetMaxUV()) : 1);
- Verify( MLRState::GetHasMaxUVs() ? (gos_vertices2uv[i].v2>=-MLRState::GetMaxUV() && gos_vertices2uv[i].v2<=MLRState::GetMaxUV()) : 1);
- if(gos_vertices2uv[i].rhw < fadeDetailEnd)
- {
- gos_vertices2uv[i].argb &= 0x00ffffff;
- }
- else
- {
- if(gos_vertices2uv[i].rhw<fadeDetailStart)
- {
- gos_vertices2uv[i].argb &= ((Stuff::Truncate_Float_To_Word((gos_vertices2uv[i].rhw - fadeDetailEnd)*fadeMultiplicator)) << 24) | 0x00ffffff;
- }
- }
- }
- if(db==false)
- {
- vt->Increase2UV(numGOSVertices);
- }
- }
- else
- {
- if(db==false)
- {
- Verify (vt->GetLast() + 2*numGOSVertices < vt->GetLength());
- }
- else
- {
- Verify (2*numGOSVertices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- memcpy(gos_vertices + numGOSVertices, gos_vertices, numGOSVertices * sizeof(GOSVertex));
- stride = 0;
- for(i=0,j=numGOSVertices;i<numGOSVertices;i++,j++)
- {
- #ifdef I_SAY_YES_TO_TERRAIN2
- gos_vertices[j].u = gos_vertices[i].u*xScale;
- gos_vertices[j].v = gos_vertices[i].v*yScale;
- #else // I_SAY_YES_TO_TERRAIN2
- gos_vertices[j].u = gos_vertices[i].u*xScale + xOffset + deltaU2;
- gos_vertices[j].v = gos_vertices[i].v*yScale + yOffset + deltaV2;
- #endif // I_SAY_YES_TO_TERRAIN2
- Verify( MLRState::GetHasMaxUVs() ? (gos_vertices[j].u>=-MLRState::GetMaxUV() && gos_vertices[j].u<=MLRState::GetMaxUV()) : 1);
- Verify( MLRState::GetHasMaxUVs() ? (gos_vertices[j].v>=-MLRState::GetMaxUV() && gos_vertices[j].v<=MLRState::GetMaxUV()) : 1);
- if(gos_vertices[j].rhw < fadeDetailEnd)
- {
- gos_vertices[j].argb &= 0x00ffffff;
- }
- else
- {
- stride++;
- if(gos_vertices[j].rhw<fadeDetailStart)
- {
- gos_vertices[j].argb &= ((Stuff::Truncate_Float_To_Word((gos_vertices[j].rhw - fadeDetailEnd)*fadeMultiplicator)) << 24) | 0x00ffffff;
- }
- }
- }
- if(stride==0)
- {
- detTextureVisible=false;
- }
- else
- {
- detTextureVisible=true;
- }
- if(db==false)
- {
- vt->Increase(2*numGOSVertices);
- }
- }
- }
- else
- {
- if(db==false)
- {
- vt->Increase(numGOSVertices);
- }
- }
- #else // I_SAY_YES_TO_DETAIL_TEXTURES
- if(db==false)
- {
- vt->Increase(numGOSVertices);
- }
- #endif // I_SAY_YES_TO_DETAIL_TEXTURES
- #endif // // I_SAY_YES_TO_DUAL_TEXTURES
- #ifdef I_SAY_YES_TO_MULTI_TEXTURES
- for(m=1;m<currentNrOfPasses;m++)
- {
- Verify (tex2count[m] == numGOSVertices);
- if(db==false)
- {
- Verify (vt->GetLast() + numGOSVertices < vt->GetLength());
- }
- else
- {
- Verify (numGOSVertices < 2*Limits::Max_Number_Vertices_Per_Mesh);
- }
- memcpy(gos_vertices + m*numGOSVertices, gos_vertices, numGOSVertices * sizeof(GOSVertex));
- for(i=0,j=numGOSVertices;i<numGOSVertices;i++,j++)
- {
- gos_vertices[j].u = extraMultiTexCoords[m][i][0];
- gos_vertices[j].v = extraMultiTexCoords[m][i][1];
- }
- if(db==false)
- {
- vt->Increase(numGOSVertices);
- }
- }
- #endif // I_SAY_YES_TO_MULTI_TEXTURES
- if(db==false)
- {
- vt->IncreaseIndex(numGOSIndices);
- }
- visible = numGOSVertices ? (unsigned char)1 : (unsigned char)0;
- if(visible)
- {
- }
- else
- {
- }
- #if 0 //def I_SAY_YES_TO_DUAL_TEXTURES
- if(MLRState::GetMultitextureLightMap() == true && state.GetMultiTextureMode()!=MLRState::MultiTextureOffMode)
- {
- CheckVertices1( gos_vertices2uv, numGOSVertices );
- }
- else
- {
- CheckVertices( gos_vertices, numGOSVertices, false );
- }
- #endif // // I_SAY_YES_TO_DUAL_TEXTURES
- Stop_Timer(Clipping_Time);
- return ret;
- }
|