Created
March 6, 2012 03:28
-
-
Save SebastienLussier/1983230 to your computer and use it in GitHub Desktop.
Dumb attempt at using OMP in ARX_PORTALS_Frustrum_RenderRoomTCullSoft()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ARX_PORTALS_Frustrum_RenderRoomTCullSoft(long room_num,EERIE_FRUSTRUM_DATA * frustrums,long prec,long tim) | |
{ | |
if (RoomDraw[room_num].count) | |
{ | |
if(!portals->room[room_num].pVertexBuffer) | |
{ | |
char tTxt[256]; | |
sprintf(tTxt,"portals %ld - Zero Polys",room_num); | |
LogError<< tTxt<<" Error Portals"; | |
return; | |
} | |
SMY_VERTEX * pMyVertex = portals->room[room_num].pVertexBuffer->lock(NoOverwrite); | |
unsigned short *pIndices = portals->room[room_num].pussIndice; | |
for (long lll=0; lll<portals->room[room_num].nb_polys; lll++) | |
{ | |
EP_DATA *pEPDATA = &portals->room[room_num].epdata[lll]; | |
FAST_BKG_DATA * feg = &ACTIVEBKG->fastdata[pEPDATA->px][pEPDATA->py]; | |
if (!feg->treat) | |
{ | |
long ix=max(0,pEPDATA->px-1); | |
long ax=min(ACTIVEBKG->Xsize-1,pEPDATA->px+1); | |
long iz=max(0,pEPDATA->py-1); | |
long az=min(ACTIVEBKG->Zsize-1,pEPDATA->py+1); | |
(void)checked_range_cast<short>(iz); | |
(void)checked_range_cast<short>(ix); | |
(void)checked_range_cast<short>(az); | |
(void)checked_range_cast<short>(ax); | |
for (long nz=iz;nz<=az;nz++) | |
{ | |
for (long nx=ix;nx<=ax;nx++) | |
{ | |
FAST_BKG_DATA * feg2 = &ACTIVEBKG->fastdata[nx][nz]; | |
if (!feg2->treat) | |
{ | |
feg2->treat=1; | |
if (USE_LIGHT_OPTIM) | |
ComputeTileLights(static_cast<short>(nx), static_cast<short>(nz)); | |
} | |
} | |
} | |
} | |
} | |
#pragma omp parallel for | |
for (long lll=0; lll<portals->room[room_num].nb_polys; lll++) | |
{ | |
EP_DATA *pEPDATA = &portals->room[room_num].epdata[lll]; | |
FAST_BKG_DATA * feg = &ACTIVEBKG->fastdata[pEPDATA->px][pEPDATA->py]; | |
EERIEPOLY *ep = &feg->polydata[pEPDATA->idx]; | |
if (!ep->tex) | |
{ | |
continue; | |
} | |
if (ep->type & (POLY_IGNORE | POLY_NODRAW| POLY_HIDE)) | |
{ | |
continue; | |
} | |
if (FrustrumsClipPoly(frustrums,ep)) | |
{ | |
continue; | |
} | |
//Clipp ZNear + Distance pour les ZMapps!!! | |
float fDist=(ep->center.x*efpPlaneNear.a + ep->center.y*efpPlaneNear.b + ep->center.z*efpPlaneNear.c + efpPlaneNear.d); | |
if(ep->v[0].rhw<-fDist) | |
{ | |
continue; | |
} | |
fDist-=ep->v[0].rhw; | |
Vec3f nrm; | |
nrm.x=ep->v[2].p.x-ACTIVECAM->pos.x; | |
nrm.y=ep->v[2].p.y-ACTIVECAM->pos.y; | |
nrm.z=ep->v[2].p.z-ACTIVECAM->pos.z; | |
int to; | |
if(ep->type&POLY_QUAD) | |
{ | |
if( (!(ep->type&POLY_DOUBLESIDED))&& | |
(dot( ep->norm , nrm )>0.f)&& | |
(dot( ep->norm2 , nrm )>0.f) ) | |
{ | |
continue; | |
} | |
to=4; | |
} | |
else | |
{ | |
if( (!(ep->type&POLY_DOUBLESIDED))&& | |
(dot( ep->norm , nrm )>0.f) ) | |
{ | |
continue; | |
} | |
to=3; | |
} | |
unsigned long volatile *pNumIndices; | |
unsigned long idxStartCull; | |
if(ep->type&POLY_TRANS) | |
{ | |
if(ep->transval>=2.f) //MULTIPLICATIVE | |
{ | |
idxStartCull = ep->tex->tMatRoom[room_num].uslStartCull_TMultiplicative; | |
pNumIndices = &ep->tex->tMatRoom[room_num].uslNbIndiceCull_TMultiplicative; | |
} | |
else | |
{ | |
if(ep->transval>=1.f) //ADDITIVE | |
{ | |
idxStartCull = ep->tex->tMatRoom[room_num].uslStartCull_TAdditive; | |
pNumIndices = &ep->tex->tMatRoom[room_num].uslNbIndiceCull_TAdditive; | |
} | |
else | |
{ | |
if(ep->transval>0.f) //NORMAL TRANS | |
{ | |
idxStartCull = ep->tex->tMatRoom[room_num].uslStartCull_TNormalTrans; | |
pNumIndices = &ep->tex->tMatRoom[room_num].uslNbIndiceCull_TNormalTrans; | |
} | |
else | |
{ | |
//SUBTRACTIVE | |
idxStartCull = ep->tex->tMatRoom[room_num].uslStartCull_TSubstractive; | |
pNumIndices = &ep->tex->tMatRoom[room_num].uslNbIndiceCull_TSubstractive; | |
} | |
} | |
} | |
} | |
else | |
{ | |
idxStartCull = ep->tex->tMatRoom[room_num].uslStartCull; | |
pNumIndices = &ep->tex->tMatRoom[room_num].uslNbIndiceCull; | |
if(ZMAPMODE) | |
{ | |
if((fDist<200)&&(ep->tex->TextureRefinement)) | |
{ | |
#pragma omp critical | |
{ | |
ep->tex->TextureRefinement->vPolyZMap.push_back(ep); | |
} | |
} | |
} | |
} | |
long offset = _InterlockedExchangeAdd((volatile long*)pNumIndices, to&4 ? 6 : 3); | |
unsigned short *pIndicesCurr = pIndices + idxStartCull + offset; | |
pIndicesCurr[0]=ep->uslInd[0]; | |
pIndicesCurr[1]=ep->uslInd[1]; | |
pIndicesCurr[2]=ep->uslInd[2]; | |
if(to&4) | |
{ | |
pIndicesCurr[3]=ep->uslInd[3]; | |
pIndicesCurr[4]=ep->uslInd[2]; | |
pIndicesCurr[5]=ep->uslInd[1]; | |
} | |
SMY_VERTEX *pMyVertexCurr = &pMyVertex[ep->tex->tMatRoom[room_num].uslStartVertex]; | |
if (!Project.improve) // Normal View... | |
{ | |
if(ep->type&POLY_GLOW) | |
{ | |
pMyVertexCurr[ep->uslInd[0]].color=pMyVertexCurr[ep->uslInd[1]].color=pMyVertexCurr[ep->uslInd[2]].color=0xFFFFFFFF; | |
if(to&4) | |
{ | |
pMyVertexCurr[ep->uslInd[3]].color=0xFFFFFFFF; | |
} | |
} | |
else | |
{ | |
if(ep->type&POLY_LAVA) | |
{ | |
if((FRAME_COUNT<=0)&&(!(ep->type&POLY_TRANS))) | |
{ | |
if(ModeLight & MODE_DYNAMICLIGHT) | |
{ | |
ApplyDynLight(ep); | |
} | |
else | |
{ | |
ep->tv[0].color=ep->v[0].color; | |
ep->tv[1].color=ep->v[1].color; | |
ep->tv[2].color=ep->v[2].color; | |
if(to&4) | |
{ | |
ep->tv[3].color=ep->v[3].color; | |
} | |
} | |
} | |
ManageLava_VertexBuffer(ep,to,tim,pMyVertexCurr); | |
#pragma omp critical | |
{ | |
vPolyLava.push_back(ep); | |
} | |
pMyVertexCurr[ep->uslInd[0]].color=ep->tv[0].color; | |
pMyVertexCurr[ep->uslInd[1]].color=ep->tv[1].color; | |
pMyVertexCurr[ep->uslInd[2]].color=ep->tv[2].color; | |
if(to&4) | |
{ | |
pMyVertexCurr[ep->uslInd[3]].color=ep->tv[3].color; | |
} | |
} | |
else | |
{ | |
if((FRAME_COUNT<=0)&&(!(ep->type&POLY_TRANS))) | |
{ | |
if(ModeLight & MODE_DYNAMICLIGHT) | |
{ | |
if (USE_LIGHT_OPTIM) | |
ApplyDynLight_VertexBuffer_2( ep, pEPDATA->px, pEPDATA->py, | |
pMyVertexCurr, | |
ep->uslInd[0], | |
ep->uslInd[1], | |
ep->uslInd[2], | |
ep->uslInd[3]); | |
else | |
ApplyDynLight_VertexBuffer( ep, | |
pMyVertexCurr, | |
ep->uslInd[0], | |
ep->uslInd[1], | |
ep->uslInd[2], | |
ep->uslInd[3]); | |
} | |
else | |
{ | |
pMyVertexCurr[ep->uslInd[0]].color=ep->v[0].color; | |
pMyVertexCurr[ep->uslInd[1]].color=ep->v[1].color; | |
pMyVertexCurr[ep->uslInd[2]].color=ep->v[2].color; | |
if(to&4) | |
{ | |
pMyVertexCurr[ep->uslInd[3]].color=ep->v[3].color; | |
} | |
} | |
} | |
if(ep->type&POLY_WATER) | |
{ | |
ManageWater_VertexBuffer(ep,to,tim,pMyVertexCurr); | |
#pragma omp critical | |
{ | |
vPolyWater.push_back(ep); | |
} | |
} | |
} | |
} | |
if ((ViewMode & VIEWMODE_WIRE)) | |
{ | |
if (EERIERTPPoly(ep)) | |
{ | |
#pragma omp critical | |
{ | |
EERIEPOLY_DrawWired(ep); | |
} | |
} | |
} | |
} | |
else // Improve Vision Activated | |
{ | |
//!!!!!!!!! NOT OPTIMIZED T&L !!!!!!!!!! | |
if ((FRAME_COUNT<=0)&&(!(ep->type&POLY_TRANS))) | |
{ | |
if (!EERIERTPPoly(ep)) // RotTransProject Vertices | |
{ | |
continue; | |
} | |
if ( ModeLight & MODE_DYNAMICLIGHT ) ApplyDynLight(ep); | |
else | |
{ | |
ep->tv[0].color=ep->v[0].color; | |
ep->tv[1].color=ep->v[1].color; | |
ep->tv[2].color=ep->v[2].color; | |
if(to&4) | |
{ | |
ep->tv[3].color=ep->v[3].color; | |
} | |
} | |
for (long k=0;k<to;k++) | |
{ | |
long lfr,lfb; | |
float fr,fb; | |
long lr=(ep->tv[k].color>>16) & 255; | |
float ffr=(float)(lr); | |
float dd=(ep->tv[k].rhw*prec); | |
if (dd>1.f) dd=1.f; | |
if (dd<0.f) dd=0.f; | |
fb=((1.f-dd)*6.f + (EEfabs(ep->nrml[k].x)+EEfabs(ep->nrml[k].y)))*0.125f; | |
fr = ((0.6f - dd) * 6.f + (EEfabs(ep->nrml[k].z) + EEfabs(ep->nrml[k].y))) * 0.125f; | |
if (fr<0.f) fr=0.f; | |
else fr=max(ffr,fr*255.f); | |
fr=min(fr,255.f); | |
fb*=255.f; | |
fb=min(fb,255.f); | |
lfr = fr; | |
lfb = fb; | |
ep->tv[k].color=( 0xff001E00L | ( (lfr & 255) << 16) | (lfb & 255) ); | |
} | |
pMyVertexCurr[ep->uslInd[0]].color=ep->tv[0].color; | |
pMyVertexCurr[ep->uslInd[1]].color=ep->tv[1].color; | |
pMyVertexCurr[ep->uslInd[2]].color=ep->tv[2].color; | |
if(to&4) | |
{ | |
pMyVertexCurr[ep->uslInd[3]].color=ep->tv[3].color; | |
} | |
} | |
} | |
} | |
portals->room[room_num].pVertexBuffer->unlock(); | |
//render opaque | |
GRenderer->SetCulling(Renderer::CullNone); | |
int iNbTex=portals->room[room_num].usNbTextures; | |
TextureContainer **ppTexCurr=portals->room[room_num].ppTextureContainer; | |
while(iNbTex--) | |
{ | |
TextureContainer *pTexCurr=*ppTexCurr; | |
if (ViewMode & VIEWMODE_FLAT) | |
GRenderer->ResetTexture(0); | |
else | |
GRenderer->SetTexture(0, pTexCurr); | |
if(pTexCurr->userflags&POLY_METAL) | |
{ | |
GRenderer->GetTextureStage(0)->SetColorOp(TextureStage::OpModulate2X); | |
} | |
else | |
{ | |
GRenderer->GetTextureStage(0)->SetColorOp(TextureStage::OpModulate); | |
} | |
if(pTexCurr->tMatRoom[room_num].uslNbIndiceCull) | |
{ | |
GRenderer->SetAlphaFunc(Renderer::CmpGreater, .5f); | |
portals->room[room_num].pVertexBuffer->drawIndexed(Renderer::TriangleList, pTexCurr->tMatRoom[room_num].uslNbVertex, pTexCurr->tMatRoom[room_num].uslStartVertex, | |
&portals->room[room_num].pussIndice[pTexCurr->tMatRoom[room_num].uslStartCull], | |
pTexCurr->tMatRoom[room_num].uslNbIndiceCull); | |
GRenderer->SetAlphaFunc(Renderer::CmpNotEqual, 0.f); | |
EERIEDrawnPolys+=pTexCurr->tMatRoom[room_num].uslNbIndiceCull; | |
pTexCurr->tMatRoom[room_num].uslNbIndiceCull=0; | |
} | |
ppTexCurr++; | |
} | |
////////////////////////////// | |
//ZMapp | |
GRenderer->GetTextureStage(0)->SetColorOp(TextureStage::OpModulate); | |
GRenderer->SetRenderState(Renderer::AlphaBlending, true); | |
GRenderer->SetRenderState(Renderer::DepthWrite, false); | |
iNbTex=portals->room[room_num].usNbTextures; | |
ppTexCurr=portals->room[room_num].ppTextureContainer; | |
while ( iNbTex-- ) //For each tex in portals->room[room_num] | |
{ | |
TextureContainer * pTexCurr = *ppTexCurr; | |
if ( pTexCurr->TextureRefinement && pTexCurr->TextureRefinement->vPolyZMap.size() ) | |
{ | |
//--------------------------------------------------------------------------- | |
// INIT | |
GRenderer->SetTexture(0, pTexCurr->TextureRefinement); | |
dynamicVertices.lock(); | |
unsigned short * pussInd = dynamicVertices.indices; | |
unsigned short iNbIndice = 0; | |
vector<EERIEPOLY *>::iterator it = pTexCurr->TextureRefinement->vPolyZMap.begin(); | |
//--------------------------------------------------------------------------- | |
// LOOP | |
for (; it != pTexCurr->TextureRefinement->vPolyZMap.end(); ++it) | |
{ | |
EERIEPOLY * ep = *it; | |
unsigned short iNbVertex = (ep->type & POLY_QUAD) ? 4 : 3; | |
SMY_VERTEX3 * pVertex = dynamicVertices.append(iNbVertex); | |
if(!pVertex) { | |
dynamicVertices.unlock(); | |
if(dynamicVertices.nbindices) { | |
dynamicVertices.draw(Renderer::TriangleList); | |
} | |
dynamicVertices.reset(); | |
dynamicVertices.lock(); | |
iNbIndice = 0; | |
pussInd = dynamicVertices.indices; | |
pVertex = dynamicVertices.append(iNbVertex); | |
} | |
//----------------------------------------------------------------------- | |
// PRECALCUL | |
float tu[4]; | |
float tv[4]; | |
float _fTransp[4]; | |
unsigned short nu; | |
long nrm=0; | |
if ( (EEfabs(ep->nrml[0].y)>=0.9f) | |
|| (EEfabs(ep->nrml[1].y)>=0.9f) | |
|| (EEfabs(ep->nrml[2].y)>=0.9f) ) | |
nrm=1; | |
for (nu=0;nu<iNbVertex;nu++) | |
{ | |
if (nrm) | |
{ | |
tu[nu]=(ep->v[nu].p.x*( 1.0f / 50 )); | |
tv[nu]=(ep->v[nu].p.z*( 1.0f / 50 )); | |
} | |
else | |
{ | |
tu[nu]=ep->v[nu].uv.x*4.f; | |
tv[nu]=ep->v[nu].uv.y*4.f; | |
} | |
float t = max(10.f, fdist(ACTIVECAM->pos, ep->v[nu].p) - 80.f); | |
_fTransp[nu] = (150.f - t) * 0.006666666f; | |
if (_fTransp[nu] < 0.f) | |
_fTransp[nu] = 0.f; | |
// t cannot be greater than 1.f (b should be negative for that) | |
} | |
//----------------------------------------------------------------------- | |
// FILL DATA | |
for ( int idx = 0 ; idx < iNbVertex ; ++idx ) | |
{ | |
pVertex->p.x = ep->v[idx].p.x; | |
pVertex->p.y = - ep->v[idx].p.y; | |
pVertex->p.z = ep->v[idx].p.z; | |
pVertex->color = Color::gray(_fTransp[idx]).toBGR(); | |
pVertex->uv[0].x = tu[idx]; | |
pVertex->uv[0].y = tv[idx]; | |
pVertex++; | |
*pussInd++ = iNbIndice++; | |
dynamicVertices.nbindices++; | |
} | |
if(iNbVertex&4) { | |
*pussInd++=iNbIndice-2; | |
*pussInd++=iNbIndice-3; | |
dynamicVertices.nbindices += 2; | |
} | |
} | |
//--------------------------------------------------------------------------- | |
// CLEAR CURRENT ZMAP | |
pTexCurr->TextureRefinement->vPolyZMap.clear(); | |
dynamicVertices.unlock(); | |
if(dynamicVertices.nbindices) { | |
dynamicVertices.draw(Renderer::TriangleList); | |
} | |
dynamicVertices.done(); | |
} | |
ppTexCurr++; | |
} //END while ( iNbTex-- ) ---------------------------------------------------------- | |
GRenderer->SetRenderState(Renderer::DepthWrite, true); | |
GRenderer->SetRenderState(Renderer::AlphaBlending, false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment