summaryrefslogtreecommitdiffstats
path: root/src/render/Renderer.cpp
diff options
context:
space:
mode:
authorerorcun <erorcunerorcun@hotmail.com.tr>2020-11-12 15:37:04 +0100
committererorcun <erorcunerorcun@hotmail.com.tr>2020-11-12 15:37:04 +0100
commit4f8029ad7c76d53f08d9f922d59db32ee27be3f2 (patch)
treed5a34f1f072e70671b33ebbff9b9d875053c6380 /src/render/Renderer.cpp
parentPeds: Remove redundant lines (diff)
parentfixed zone bug (diff)
downloadre3-4f8029ad7c76d53f08d9f922d59db32ee27be3f2.tar
re3-4f8029ad7c76d53f08d9f922d59db32ee27be3f2.tar.gz
re3-4f8029ad7c76d53f08d9f922d59db32ee27be3f2.tar.bz2
re3-4f8029ad7c76d53f08d9f922d59db32ee27be3f2.tar.lz
re3-4f8029ad7c76d53f08d9f922d59db32ee27be3f2.tar.xz
re3-4f8029ad7c76d53f08d9f922d59db32ee27be3f2.tar.zst
re3-4f8029ad7c76d53f08d9f922d59db32ee27be3f2.zip
Diffstat (limited to 'src/render/Renderer.cpp')
-rw-r--r--src/render/Renderer.cpp659
1 files changed, 641 insertions, 18 deletions
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 3b996b55..c2982d6d 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -1,3 +1,4 @@
+#define WITH_D3D
#include "common.h"
#include "main.h"
@@ -6,6 +7,7 @@
#include "Treadable.h"
#include "Ped.h"
#include "Vehicle.h"
+#include "Boat.h"
#include "Heli.h"
#include "Bike.h"
#include "Object.h"
@@ -47,12 +49,27 @@ int32 CRenderer::ms_nNoOfVisibleEntities;
CEntity *CRenderer::ms_aVisibleEntityPtrs[NUMVISIBLEENTITIES];
CEntity *CRenderer::ms_aInVisibleEntityPtrs[NUMINVISIBLEENTITIES];
int32 CRenderer::ms_nNoOfInVisibleEntities;
+#ifdef NEW_RENDERER
+int32 CRenderer::ms_nNoOfVisibleVehicles;
+CEntity *CRenderer::ms_aVisibleVehiclePtrs[NUMVISIBLEENTITIES];
+int32 CRenderer::ms_nNoOfVisibleBuildings;
+CEntity *CRenderer::ms_aVisibleBuildingPtrs[NUMVISIBLEENTITIES];
+#endif
CVector CRenderer::ms_vecCameraPosition;
CVehicle *CRenderer::m_pFirstPersonVehicle;
bool CRenderer::m_loadingPriority;
float CRenderer::ms_lodDistScale = 1.2f;
+#ifdef FIX_BUGS
+#define LOD_DISTANCE (300.0f*TheCamera.LODDistMultiplier)
+#else
+#define LOD_DISTANCE 300.0f
+#endif
+#define FADE_DISTANCE 20.0f
+#define STREAM_DISTANCE 30.0f
+
+
void
CRenderer::Init(void)
{
@@ -75,6 +92,20 @@ CRenderer::PreRender(void)
for(i = 0; i < ms_nNoOfVisibleEntities; i++)
ms_aVisibleEntityPtrs[i]->PreRender();
+#ifdef NEW_RENDERER
+ if(gbNewRenderer){
+ for(i = 0; i < ms_nNoOfVisibleVehicles; i++)
+ ms_aVisibleVehiclePtrs[i]->PreRender();
+ // How is this done with cWorldStream?
+ for(i = 0; i < ms_nNoOfVisibleBuildings; i++)
+ ms_aVisibleBuildingPtrs[i]->PreRender();
+ for(node = CVisibilityPlugins::m_alphaBuildingList.head.next;
+ node != &CVisibilityPlugins::m_alphaBuildingList.tail;
+ node = node->next)
+ ((CEntity*)node->item.entity)->PreRender();
+ }
+#endif
+
for (i = 0; i < ms_nNoOfInVisibleEntities; i++) {
#ifdef SQUEEZE_PERFORMANCE
if (ms_aInVisibleEntityPtrs[i]->IsVehicle() && ((CVehicle*)ms_aInVisibleEntityPtrs[i])->IsHeli())
@@ -230,7 +261,6 @@ CRenderer::RenderEverythingBarRoads(void)
{
int i;
CEntity *e;
- CVector dist;
EntityInfo ei;
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
@@ -253,12 +283,10 @@ CRenderer::RenderEverythingBarRoads(void)
e->IsPed() && CVisibilityPlugins::GetClumpAlpha((RpClump*)e->m_rwObject) != 255){
if(e->IsVehicle() && PutIntoSortedVehicleList((CVehicle*)e)){
ei.ent = e;
- dist = ms_vecCameraPosition - e->GetPosition();
- ei.sort = dist.MagnitudeSqr();
+ ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr();
gSortedVehiclesAndPeds.InsertSorted(ei);
}else{
- dist = ms_vecCameraPosition - e->GetPosition();
- if(!CVisibilityPlugins::InsertEntityIntoSortedList(e, dist.Magnitude())){
+ if(!CVisibilityPlugins::InsertEntityIntoSortedList(e, (ms_vecCameraPosition - e->GetPosition()).Magnitude())){
printf("Ran out of space in alpha entity list");
RenderOneNonRoad(e);
}
@@ -277,6 +305,24 @@ CRenderer::RenderBoats(void)
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
SetCullMode(rwCULLMODECULLBACK);
+#ifdef NEW_RENDERER
+ int i;
+ CEntity *e;
+ EntityInfo ei;
+ if(gbNewRenderer){
+ gSortedVehiclesAndPeds.Clear();
+ // not the real thing
+ for(i = 0; i < ms_nNoOfVisibleVehicles; i++){
+ e = ms_aVisibleVehiclePtrs[i];
+ if(e->IsVehicle() && PutIntoSortedVehicleList((CVehicle*)e)){
+ ei.ent = e;
+ ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr();
+ gSortedVehiclesAndPeds.InsertSorted(ei);
+ }
+ }
+ }
+#endif
+
for(node = gSortedVehiclesAndPeds.tail.prev;
node != &gSortedVehiclesAndPeds.head;
node = node->prev){
@@ -285,6 +331,573 @@ CRenderer::RenderBoats(void)
}
}
+#ifdef NEW_RENDERER
+#ifndef LIBRW
+#error "Need librw for EXTENDED_PIPELINES"
+#endif
+#include "WaterLevel.h"
+
+enum {
+ // blend passes
+ PASS_NOZ, // no z-write
+ PASS_ADD, // additive
+ PASS_BLEND // normal blend
+};
+
+static RwRGBAReal black;
+
+#ifdef RW_D3D9
+struct BuildingInst
+{
+ rw::RawMatrix combinedMat;
+ rw::d3d9::InstanceDataHeader *instHeader;
+ uint8 fadeAlpha;
+ bool lighting;
+};
+static BuildingInst blendInsts[3][2000];
+static int numBlendInsts[3];
+
+static void
+SetStencilState(int state)
+{
+ switch(state){
+ // disable stencil
+ case 0:
+ rw::d3d::setRenderState(D3DRS_STENCILENABLE, FALSE);
+ break;
+ // test against stencil
+ case 1:
+ rw::d3d::setRenderState(D3DRS_STENCILENABLE, TRUE);
+ rw::d3d::setRenderState(D3DRS_STENCILFUNC, D3DCMP_NOTEQUAL);
+ rw::d3d::setRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
+ rw::d3d::setRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
+ rw::d3d::setRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
+ rw::d3d::setRenderState(D3DRS_STENCILMASK, 0xFF);
+ rw::d3d::setRenderState(D3DRS_STENCILREF, 0xFF);
+ break;
+ // write to stencil
+ case 2:
+ rw::d3d::setRenderState(D3DRS_STENCILENABLE, TRUE);
+ rw::d3d::setRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
+ rw::d3d::setRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);
+ rw::d3d::setRenderState(D3DRS_STENCILREF, 0xFF);
+ break;
+ }
+}
+
+static void
+SetMatrix(BuildingInst *building, rw::Matrix *worldMat)
+{
+ using namespace rw;
+ RawMatrix world, worldview;
+ Camera *cam = engine->currentCamera;
+ convMatrix(&world, worldMat);
+ RawMatrix::mult(&worldview, &world, &cam->devView);
+ RawMatrix::mult(&building->combinedMat, &worldview, &cam->devProj);
+}
+
+static bool
+IsTextureTransparent(RwTexture *tex)
+{
+ if(tex == nil || tex->raster == nil)
+ return false;
+ return PLUGINOFFSET(rw::d3d::D3dRaster, tex->raster, rw::d3d::nativeRasterOffset)->hasAlpha;
+}
+
+// Render all opaque meshes and put atomics that needs blending
+// into the deferred list.
+static void
+AtomicFirstPass(RpAtomic *atomic, int pass)
+{
+ using namespace rw;
+ using namespace rw::d3d;
+ using namespace rw::d3d9;
+
+ BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
+
+ atomic->getPipeline()->instance(atomic);
+ building->instHeader = (d3d9::InstanceDataHeader*)atomic->geometry->instData;
+ assert(building->instHeader != nil);
+ assert(building->instHeader->platform == PLATFORM_D3D9);
+ building->fadeAlpha = 255;
+ building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
+
+ bool setupDone = false;
+ bool defer = false;
+ SetMatrix(building, atomic->getFrame()->getLTM());
+
+ InstanceData *inst = building->instHeader->inst;
+ for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){
+ Material *m = inst->material;
+
+ if(inst->vertexAlpha || m->color.alpha != 255 ||
+ IsTextureTransparent(m->texture)){
+ defer = true;
+ continue;
+ }
+
+ // alright we're rendering this atomic
+ if(!setupDone){
+ setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride);
+ setIndices(building->instHeader->indexBuffer);
+ setVertexDeclaration(building->instHeader->vertexDeclaration);
+ setVertexShader(default_amb_VS);
+ d3ddevice->SetVertexShaderConstantF(VSLOC_combined, (float*)&building->combinedMat, 4);
+ if(building->lighting)
+ setAmbient(pAmbient->color);
+ else
+ setAmbient(black);
+ setupDone = true;
+ }
+
+ setMaterial(m->color, m->surfaceProps);
+
+ if(m->texture){
+ d3d::setTexture(0, m->texture);
+ setPixelShader(default_tex_PS);
+ }else
+ setPixelShader(default_PS);
+
+ drawInst(building->instHeader, inst);
+ }
+ if(defer)
+ numBlendInsts[pass]++;
+}
+
+static void
+AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha)
+{
+ using namespace rw;
+ using namespace rw::d3d;
+ using namespace rw::d3d9;
+
+ BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
+
+ atomic->getPipeline()->instance(atomic);
+ building->instHeader = (d3d9::InstanceDataHeader*)atomic->geometry->instData;
+ assert(building->instHeader != nil);
+ assert(building->instHeader->platform == PLATFORM_D3D9);
+ building->fadeAlpha = fadeAlpha;
+ building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
+ SetMatrix(building, atomic->getFrame()->getLTM());
+ numBlendInsts[pass]++;
+}
+
+static void
+RenderBlendPass(int pass)
+{
+ using namespace rw;
+ using namespace rw::d3d;
+ using namespace rw::d3d9;
+
+ setVertexShader(default_amb_VS);
+
+ int i;
+ for(i = 0; i < numBlendInsts[pass]; i++){
+ BuildingInst *building = &blendInsts[pass][i];
+
+ setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride);
+ setIndices(building->instHeader->indexBuffer);
+ setVertexDeclaration(building->instHeader->vertexDeclaration);
+ d3ddevice->SetVertexShaderConstantF(VSLOC_combined, (float*)&building->combinedMat, 4);
+ if(building->lighting)
+ setAmbient(pAmbient->color);
+ else
+ setAmbient(black);
+
+ InstanceData *inst = building->instHeader->inst;
+ for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){
+ Material *m = inst->material;
+ if(!inst->vertexAlpha && m->color.alpha == 255 && !IsTextureTransparent(m->texture) && building->fadeAlpha == 255)
+ continue; // already done this one
+
+ rw::RGBA color = m->color;
+ color.alpha = (color.alpha * building->fadeAlpha)/255;
+ setMaterial(color, m->surfaceProps);
+
+ if(m->texture){
+ d3d::setTexture(0, m->texture);
+ setPixelShader(default_tex_PS);
+ }else
+ setPixelShader(default_PS);
+
+ drawInst(building->instHeader, inst);
+ }
+ }
+}
+#endif
+#ifdef RW_GL3
+struct BuildingInst
+{
+ rw::Matrix matrix;
+ rw::gl3::InstanceDataHeader *instHeader;
+ uint8 fadeAlpha;
+ bool lighting;
+};
+static BuildingInst blendInsts[3][2000];
+static int numBlendInsts[3];
+
+static void
+SetStencilState(int state)
+{
+ switch(state){
+ // disable stencil
+ case 0:
+ glDisable(GL_STENCIL_TEST);
+ break;
+ // test against stencil
+ case 1:
+ glEnable(GL_STENCIL_TEST);
+ glStencilFunc(GL_NOTEQUAL, 0xFF, 0xFF);
+ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+ glStencilMask(0xFF);
+ break;
+ // write to stencil
+ case 2:
+ glEnable(GL_STENCIL_TEST);
+ glStencilFunc(GL_ALWAYS, 0xFF, 0xFF);
+ glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
+ break;
+ }
+}
+
+static bool
+IsTextureTransparent(RwTexture *tex)
+{
+ if(tex == nil || tex->raster == nil)
+ return false;
+ return PLUGINOFFSET(rw::gl3::Gl3Raster, tex->raster, rw::gl3::nativeRasterOffset)->hasAlpha;
+}
+
+// Render all opaque meshes and put atomics that needs blending
+// into the deferred list.
+static void
+AtomicFirstPass(RpAtomic *atomic, int pass)
+{
+ using namespace rw;
+ using namespace rw::gl3;
+
+ BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
+
+ atomic->getPipeline()->instance(atomic);
+ building->instHeader = (gl3::InstanceDataHeader*)atomic->geometry->instData;
+ assert(building->instHeader != nil);
+ assert(building->instHeader->platform == PLATFORM_GL3);
+ building->fadeAlpha = 255;
+ building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
+
+ WorldLights lights;
+ lights.numAmbients = 1;
+ lights.numDirectionals = 0;
+ lights.numLocals = 0;
+ if(building->lighting)
+ lights.ambient = pAmbient->color;
+ else
+ lights.ambient = black;
+
+ bool setupDone = false;
+ bool defer = false;
+ building->matrix = *atomic->getFrame()->getLTM();
+
+ InstanceData *inst = building->instHeader->inst;
+ for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){
+ Material *m = inst->material;
+
+ if(inst->vertexAlpha || m->color.alpha != 255 ||
+ IsTextureTransparent(m->texture)){
+ defer = true;
+ continue;
+ }
+
+ // alright we're rendering this atomic
+ if(!setupDone){
+ defaultShader->use();
+ setWorldMatrix(&building->matrix);
+#ifdef RW_GL_USE_VAOS
+ glBindVertexArray(building->instHeader->vao);
+#else
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, building->instHeader->ibo);
+ glBindBuffer(GL_ARRAY_BUFFER, building->instHeader->vbo);
+ setAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
+#endif
+ setLights(&lights);
+ setupDone = true;
+ }
+
+ setMaterial(m->color, m->surfaceProps);
+
+ setTexture(0, m->texture);
+
+ drawInst(building->instHeader, inst);
+ }
+#ifndef RW_GL_USE_VAOS
+ disableAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
+#endif
+ if(defer)
+ numBlendInsts[pass]++;
+}
+
+static void
+AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha)
+{
+ using namespace rw;
+ using namespace rw::gl3;
+
+ BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
+
+ atomic->getPipeline()->instance(atomic);
+ building->instHeader = (gl3::InstanceDataHeader*)atomic->geometry->instData;
+ assert(building->instHeader != nil);
+ assert(building->instHeader->platform == PLATFORM_GL3);
+ building->fadeAlpha = fadeAlpha;
+ building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
+ building->matrix = *atomic->getFrame()->getLTM();
+ numBlendInsts[pass]++;
+}
+
+static void
+RenderBlendPass(int pass)
+{
+ using namespace rw;
+ using namespace rw::gl3;
+
+ defaultShader->use();
+ WorldLights lights;
+ lights.numAmbients = 1;
+ lights.numDirectionals = 0;
+ lights.numLocals = 0;
+
+ int i;
+ for(i = 0; i < numBlendInsts[pass]; i++){
+ BuildingInst *building = &blendInsts[pass][i];
+
+#ifdef RW_GL_USE_VAOS
+ glBindVertexArray(building->instHeader->vao);
+#else
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, building->instHeader->ibo);
+ glBindBuffer(GL_ARRAY_BUFFER, building->instHeader->vbo);
+ setAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
+#endif
+ setWorldMatrix(&building->matrix);
+ if(building->lighting)
+ lights.ambient = pAmbient->color;
+ else
+ lights.ambient = black;
+ setLights(&lights);
+
+ InstanceData *inst = building->instHeader->inst;
+ for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){
+ Material *m = inst->material;
+ if(!inst->vertexAlpha && m->color.alpha == 255 && !IsTextureTransparent(m->texture) && building->fadeAlpha == 255)
+ continue; // already done this one
+
+ rw::RGBA color = m->color;
+ color.alpha = (color.alpha * building->fadeAlpha)/255;
+ setMaterial(color, m->surfaceProps);
+
+ setTexture(0, m->texture);
+
+ drawInst(building->instHeader, inst);
+ }
+#ifndef RW_GL_USE_VAOS
+ disableAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
+#endif
+ }
+}
+#endif
+
+void
+CRenderer::RenderOneBuilding(CEntity *ent, float camdist)
+{
+ if(ent->m_rwObject == nil)
+ return;
+ assert(RwObjectGetType(ent->m_rwObject) == rpATOMIC);
+ RpAtomic *atomic = (RpAtomic*)ent->m_rwObject;
+ CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->GetModelIndex());
+
+ ent->bImBeingRendered = true; // TODO: this seems wrong, but do we even need it?
+
+ int pass = PASS_BLEND;
+ if(mi->m_additive) // very questionable
+ pass = PASS_ADD;
+ if(mi->m_noZwrite)
+ pass = PASS_NOZ;
+
+ if(ent->bDistanceFade){
+ RpAtomic *lodatm;
+ float fadefactor;
+ uint32 alpha;
+
+ lodatm = mi->GetAtomicFromDistance(camdist - FADE_DISTANCE);
+ fadefactor = (mi->GetLargestLodDistance() - (camdist - FADE_DISTANCE))/FADE_DISTANCE;
+ if(fadefactor > 1.0f)
+ fadefactor = 1.0f;
+ alpha = mi->m_alpha * fadefactor;
+
+ if(alpha == 255)
+ AtomicFirstPass(atomic, pass);
+ else{
+ // not quite sure what this is about, do we have to do that?
+ RpGeometry *geo = RpAtomicGetGeometry(lodatm);
+ if(geo != RpAtomicGetGeometry(atomic))
+ RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE);
+ AtomicFullyTransparent(atomic, pass, alpha);
+ }
+ }else
+ AtomicFirstPass(atomic, pass);
+
+ ent->bImBeingRendered = false; // TODO: this seems wrong, but do we even need it?
+}
+
+void
+CRenderer::RenderWorld(int pass)
+{
+ int i;
+ CEntity *e;
+ CLink<CVisibilityPlugins::AlphaObjectInfo> *node;
+
+ RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
+ SetCullMode(rwCULLMODECULLBACK);
+ DeActivateDirectional();
+ SetAmbientColours();
+
+ // Temporary...have to figure out sorting better
+ switch(pass){
+ case 0:
+ // Roads
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE);
+ for(i = 0; i < ms_nNoOfVisibleBuildings; i++){
+ e = ms_aVisibleBuildingPtrs[i];
+ if(e->bIsBIGBuilding || IsRoad(e))
+ RenderOneBuilding(e);
+ }
+ for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev;
+ node != &CVisibilityPlugins::m_alphaBuildingList.head;
+ node = node->prev){
+ e = node->item.entity;
+ if(e->bIsBIGBuilding || IsRoad(e))
+ RenderOneBuilding(e, node->item.sort);
+ }
+ break;
+ case 1:
+ // Opaque
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE);
+ for(i = 0; i < ms_nNoOfVisibleBuildings; i++){
+ e = ms_aVisibleBuildingPtrs[i];
+ if(!(e->bIsBIGBuilding || IsRoad(e)))
+ RenderOneBuilding(e);
+ }
+ for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev;
+ node != &CVisibilityPlugins::m_alphaBuildingList.head;
+ node = node->prev){
+ e = node->item.entity;
+ if(!(e->bIsBIGBuilding || IsRoad(e)))
+ RenderOneBuilding(e, node->item.sort);
+ }
+ // Now we have iterated through all visible buildings (unsorted and sorted)
+ // and the transparency list is done.
+
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
+ RenderBlendPass(PASS_NOZ);
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
+ break;
+ case 2:
+ // Transparent
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
+ RenderBlendPass(PASS_ADD);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
+ RenderBlendPass(PASS_BLEND);
+ break;
+ }
+}
+
+void
+CRenderer::RenderPeds(void)
+{
+ int i;
+ CEntity *e;
+
+ for(i = 0; i < ms_nNoOfVisibleVehicles; i++){
+ e = ms_aVisibleVehiclePtrs[i];
+ if(e->IsPed())
+ RenderOneNonRoad(e);
+ }
+}
+
+void
+CRenderer::RenderVehicles(void)
+{
+ int i;
+ CEntity *e;
+ EntityInfo ei;
+ CLink<EntityInfo> *node;
+
+ // not the real thing
+ for(i = 0; i < ms_nNoOfVisibleVehicles; i++){
+ e = ms_aVisibleVehiclePtrs[i];
+ if(!e->IsVehicle())
+ continue;
+ if(PutIntoSortedVehicleList((CVehicle*)e))
+ continue; // boats handled elsewhere
+ ei.ent = e;
+ ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr();
+ gSortedVehiclesAndPeds.InsertSorted(ei);
+ }
+
+ for(node = gSortedVehiclesAndPeds.tail.prev;
+ node != &gSortedVehiclesAndPeds.head;
+ node = node->prev)
+ RenderOneNonRoad(node->item.ent);
+}
+
+void
+CRenderer::RenderTransparentWater(void)
+{
+ int i;
+ CEntity *e;
+
+ RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil);
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
+ RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE);
+ RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDZERO);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE);
+ SetStencilState(2);
+
+ for(i = 0; i < ms_nNoOfVisibleVehicles; i++){
+ e = ms_aVisibleVehiclePtrs[i];
+ if(e->IsVehicle() && ((CVehicle*)e)->IsBoat())
+ ((CBoat*)e)->RenderWaterOutPolys();
+ }
+
+ RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
+ RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
+ SetStencilState(1);
+
+ CWaterLevel::RenderTransparentWater();
+
+ SetStencilState(0);
+}
+
+void
+CRenderer::ClearForFrame(void)
+{
+ ms_nNoOfVisibleEntities = 0;
+ ms_nNoOfVisibleVehicles = 0;
+ ms_nNoOfVisibleBuildings = 0;
+ ms_nNoOfInVisibleEntities = 0;
+ gSortedVehiclesAndPeds.Clear();
+
+ numBlendInsts[PASS_NOZ] = 0;
+ numBlendInsts[PASS_ADD] = 0;
+ numBlendInsts[PASS_BLEND] = 0;
+}
+#endif
+
void
CRenderer::RenderFadingInEntities(void)
{
@@ -327,14 +940,6 @@ enum Visbility
VIS_STREAMME
};
-#ifdef FIX_BUGS
-#define LOD_DISTANCE (300.0f*TheCamera.LODDistMultiplier)
-#else
-#define LOD_DISTANCE 300.0f
-#endif
-#define FADE_DISTANCE 20.0f
-#define STREAM_DISTANCE 30.0f
-
// Time Objects can be time culled if
// other == -1 || CModelInfo::GetModelInfo(other)->GetRwObject()
// i.e. we have to draw even at the wrong time if
@@ -640,9 +1245,13 @@ void
CRenderer::ConstructRenderList(void)
{
COcclusion::ProcessBeforeRendering();
-
+#ifdef NEW_RENDERER
+ if(!gbNewRenderer)
+#endif
+{
ms_nNoOfVisibleEntities = 0;
ms_nNoOfInVisibleEntities = 0;
+}
ms_vecCameraPosition = TheCamera.GetPosition();
// TODO: blocked ranges, but unused
ScanWorld();
@@ -1042,6 +1651,20 @@ CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrL
}
void
+CRenderer::InsertEntityIntoList(CEntity *ent)
+{
+#ifdef NEW_RENDERER
+ // TODO: there are more flags being checked here
+ if(gbNewRenderer && (ent->IsVehicle() || ent->IsPed()))
+ ms_aVisibleVehiclePtrs[ms_nNoOfVisibleVehicles++] = ent;
+ else if(gbNewRenderer && ent->IsBuilding())
+ ms_aVisibleBuildingPtrs[ms_nNoOfVisibleBuildings++] = ent;
+ else
+#endif
+ ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent;
+}
+
+void
CRenderer::ScanBigBuildingList(CPtrList &list)
{
CPtrNode *node;
@@ -1058,7 +1681,7 @@ CRenderer::ScanBigBuildingList(CPtrList &list)
vis = VIS_VISIBLE;
switch(vis){
case VIS_VISIBLE:
- ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent;
+ InsertEntityIntoList(ent);
ent->bOffscreen = false;
break;
case VIS_STREAMME:
@@ -1089,7 +1712,7 @@ CRenderer::ScanSectorList(CPtrList *lists)
switch(SetupEntityVisibility(ent)){
case VIS_VISIBLE:
- ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent;
+ InsertEntityIntoList(ent);
break;
case VIS_INVISIBLE:
if(!IsGlass(ent->GetModelIndex()))
@@ -1134,7 +1757,7 @@ CRenderer::ScanSectorList_Priority(CPtrList *lists)
switch(SetupEntityVisibility(ent)){
case VIS_VISIBLE:
- ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent;
+ InsertEntityIntoList(ent);
break;
case VIS_INVISIBLE:
if(!IsGlass(ent->GetModelIndex()))
@@ -1181,7 +1804,7 @@ CRenderer::ScanSectorList_Subway(CPtrList *lists)
ent->bOffscreen = false;
switch(SetupEntityVisibility(ent)){
case VIS_VISIBLE:
- ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent;
+ InsertEntityIntoList(ent);
break;
case VIS_OFFSCREEN:
ent->bOffscreen = true;