From 08bfde34a3a170f83a3aca80e26be18d18af512f Mon Sep 17 00:00:00 2001 From: turanszkij Date: Mon, 30 Nov 2015 00:18:20 +0100 Subject: [PATCH] small update --- WickedEngine/wiEmittedParticle.cpp | 6 +-- WickedEngine/wiEmittedParticle.h | 2 +- WickedEngine/wiHairParticle.cpp | 2 +- WickedEngine/wiLoader.h | 6 +++ WickedEngine/wiRenderer.cpp | 60 ++++++++++++------------------ WickedEngine/wiRenderer.h | 4 +- 6 files changed, 37 insertions(+), 43 deletions(-) diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index e97f616f4..920e38e5a 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -231,10 +231,8 @@ void wiEmittedParticle::Draw(Camera* camera, ID3D11DeviceContext *context, ID3D1 { if(!points.empty()){ - Frustum frustum = Frustum(); - frustum.ConstructFrustum(camera->zFarP,camera->Projection,camera->View); - if(frustum.CheckBox(bounding_box->corners)){ + if(camera->frustum.CheckBox(bounding_box->corners)){ vector renderPoints=vector(points.begin(),points.end()); wiRenderer::UpdateBuffer(vertexBuffer,renderPoints.data(),context,sizeof(Point)* renderPoints.size()); @@ -590,7 +588,7 @@ void wiEmittedParticle::CleanUpStatic() if(blendStateAlpha) blendStateAlpha->Release(); blendStateAlpha = NULL; if(depthStencilState) depthStencilState->Release(); depthStencilState = NULL; } -long wiEmittedParticle::getNumwiParticles() +long wiEmittedParticle::getNumParticles() { long retval=0; for(wiEmittedParticle* e:systems) diff --git a/WickedEngine/wiEmittedParticle.h b/WickedEngine/wiEmittedParticle.h index 7c917c3a9..27c0c306e 100644 --- a/WickedEngine/wiEmittedParticle.h +++ b/WickedEngine/wiEmittedParticle.h @@ -91,7 +91,7 @@ public: static void CleanUpStatic(); long getCount(); - static long getNumwiParticles(); + static long getNumParticles(); void Update(float gamespeed); void Burst(float num); diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index 5b5e598a7..fead2c43a 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -453,7 +453,7 @@ void wiHairParticle::SetUpPatches() void wiHairParticle::Draw(Camera* camera, ID3D11DeviceContext *context) { - static Frustum frustum = Frustum(); + Frustum frustum = Frustum(); frustum.ConstructFrustum((float)LOD[2], camera->Projection, camera->View); diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index 395e06a98..099f1fb95 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -7,6 +7,7 @@ #include "wiGraphicsThreads.h" #include "wiStencilRef.h" #include "wiMath.h" +#include "wiFrustum.h" struct HitSphere; class wiParticle; @@ -846,6 +847,7 @@ struct Camera:public Transform{ XMFLOAT3 At, Up; float width, height; float zNearP, zFarP; + Frustum frustum; Camera():Transform(){ } @@ -901,6 +903,8 @@ struct Camera:public Transform{ XMStoreFloat4x4(&this->View, View); XMStoreFloat3(&this->At, At); XMStoreFloat3(&this->Up, Up); + + frustum.ConstructFrustum(zFarP, Projection, this->View); } void Move(const XMVECTOR& movevector) { @@ -934,6 +938,8 @@ struct Camera:public Transform{ XMStoreFloat4x4(&this->View, View); XMStoreFloat3(&this->At, At); XMStoreFloat3(&this->Up, Up); + + frustum.ConstructFrustum(zFarP, Projection, this->View); } XMVECTOR GetEye() diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 4ecae425c..92bc00291 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -2743,13 +2743,10 @@ void wiRenderer::DrawVolumeLights(Camera* camera, ID3D11DeviceContext* context) void wiRenderer::DrawLensFlares(ID3D11DeviceContext* context, ID3D11ShaderResourceView* depth, const int& RENDERWIDTH, const int& RENDERHEIGHT){ - Frustum frustum = Frustum(); - frustum.ConstructFrustum(cam->zFarP,cam->Projection,cam->View); - CulledList culledObjects; if(spTree_lights) - wiSPTree::getVisible(spTree_lights->root,frustum,culledObjects); + wiSPTree::getVisible(spTree_lights->root,cam->frustum,culledObjects); for(Cullable* c:culledObjects) { @@ -2802,13 +2799,9 @@ void wiRenderer::DrawForShadowMap(ID3D11DeviceContext* context) { if (GameSpeed) { - Frustum frustum = Frustum(); - frustum.ConstructFrustum(cam->zFarP, cam->Projection, cam->View); - - CulledList culledLights; if (spTree_lights) - wiSPTree::getVisible(spTree_lights->root, frustum, culledLights); + wiSPTree::getVisible(spTree_lights->root, cam->frustum, culledLights); if (culledLights.size() > 0) { @@ -2934,7 +2927,8 @@ void wiRenderer::DrawForShadowMap(ID3D11DeviceContext* context) - MaterialCB mcb = MaterialCB(*iMat, m); + static MaterialCB mcb; + mcb.Create(*iMat, m); UpdateBuffer(matCb, &mcb, context); @@ -3038,7 +3032,8 @@ void wiRenderer::DrawForShadowMap(ID3D11DeviceContext* context) - MaterialCB mcb = MaterialCB(*iMat, m); + static MaterialCB mcb; + mcb.Create(*iMat, m); UpdateBuffer(matCb, &mcb, context); @@ -3140,7 +3135,8 @@ void wiRenderer::DrawForShadowMap(ID3D11DeviceContext* context) if (!wireRender && !iMat->isSky && !iMat->water && iMat->cast_shadow) { BindTexturePS(iMat->texture, 0, context); - MaterialCB mcb = MaterialCB(*iMat, m); + static MaterialCB mcb; + mcb.Create(*iMat, m); UpdateBuffer(matCb, &mcb, context); @@ -3453,13 +3449,10 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, ID3D11Device if(objects.empty()) return; - Frustum frustum = Frustum(); - frustum.ConstructFrustum(camera->zFarP,camera->Projection,camera->View); - CulledCollection culledwiRenderer; CulledList culledObjects; if(spTree) - wiSPTree::getVisible(spTree->root,frustum,culledObjects); + wiSPTree::getVisible(spTree->root, camera->frustum,culledObjects); //wiSPTree::getAll(spTree->root,culledObjects); if(!culledObjects.empty()) @@ -3591,11 +3584,11 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, ID3D11Device BindDepthStencilState(depthStencilState,mesh->stencilRef,context); - MaterialCB* mcb = new MaterialCB(*iMat,m); + static MaterialCB mcb[GRAPHICSTHREAD_COUNT]; + mcb[thread].Create(*iMat,m); - UpdateBuffer(matCb,mcb,context); + UpdateBuffer(matCb,&mcb[thread],context); - delete mcb; if(!wireRender) BindTexturePS(iMat->texture,3,context); if(!wireRender) BindTexturePS(iMat->refMap,4,context); @@ -3626,13 +3619,11 @@ void wiRenderer::DrawWorldWater(Camera* camera, ID3D11ShaderResourceView* refrac if(objects_water.empty()) return; - Frustum frustum = Frustum(); - frustum.ConstructFrustum(camera->zFarP, camera->Projection, camera->View); CulledCollection culledwiRenderer; CulledList culledObjects; if(spTree_water) - wiSPTree::getVisible(spTree_water->root,frustum,culledObjects); + wiSPTree::getVisible(spTree_water->root, camera->frustum,culledObjects); if(!culledObjects.empty()) { @@ -3701,10 +3692,11 @@ void wiRenderer::DrawWorldWater(Camera* camera, ID3D11ShaderResourceView* refrac if(iMat->water){ - MaterialCB* mcb = new MaterialCB(*iMat,m); - UpdateBuffer(matCb,mcb,context); - _aligned_free(mcb); + static MaterialCB mcb[GRAPHICSTHREAD_COUNT]; + mcb[GRAPHICSTHREAD_MISC1].Create(*iMat, m); + + UpdateBuffer(matCb, &mcb[GRAPHICSTHREAD_MISC1], context); if(!wireRender) BindTexturePS(iMat->texture,3,context); if(!wireRender) BindTexturePS(iMat->refMap,4,context); @@ -3726,13 +3718,11 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, ID3D11ShaderResourceView* if(objects_trans.empty()) return; - Frustum frustum = Frustum(); - frustum.ConstructFrustum(camera->zFarP,camera->Projection,camera->View); CulledCollection culledwiRenderer; CulledList culledObjects; if(spTree_trans) - wiSPTree::getVisible(spTree_trans->root,frustum,culledObjects); + wiSPTree::getVisible(spTree_trans->root, camera->frustum,culledObjects); if(!culledObjects.empty()) { @@ -3806,11 +3796,11 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, ID3D11ShaderResourceView* if(iMat->transparent && iMat->alpha>0 && !iMat->water && !iMat->isSky){ - - MaterialCB* mcb = new MaterialCB(*iMat,m); - UpdateBuffer(matCb,mcb,context); - _aligned_free(mcb); + static MaterialCB mcb[GRAPHICSTHREAD_COUNT]; + mcb[GRAPHICSTHREAD_MISC1].Create(*iMat, m); + + UpdateBuffer(matCb, &mcb[GRAPHICSTHREAD_MISC1], context); if(!wireRender) BindTexturePS(iMat->texture,3,context); if(!wireRender) BindTexturePS(iMat->refMap,4,context); @@ -3854,8 +3844,6 @@ void wiRenderer::DrawSky(ID3D11DeviceContext* context) void wiRenderer::DrawDecals(Camera* camera, DeviceContext context, TextureView depth) { if(!decals.empty()){ - Frustum frustum = Frustum(); - frustum.ConstructFrustum(camera->zFarP, camera->Projection, camera->View); BindTexturePS(depth,1,context); BindSamplerPS(ssClampAni,0,context); @@ -3872,7 +3860,7 @@ void wiRenderer::DrawDecals(Camera* camera, DeviceContext context, TextureView d for(Decal* decal : decals){ - if((decal->texture || decal->normal) && frustum.CheckBox(decal->bounds.corners)){ + if((decal->texture || decal->normal) && camera->frustum.CheckBox(decal->bounds.corners)){ BindTexturePS(decal->texture,2,context); BindTexturePS(decal->normal,3,context); @@ -4451,7 +4439,7 @@ void wiRenderer::SychronizeWithPhysicsEngine() } } -wiRenderer::MaterialCB::MaterialCB(const Material& mat,UINT materialIndex){ +void wiRenderer::MaterialCB::Create(const Material& mat,UINT materialIndex){ difColor = XMFLOAT4(mat.diffuseColor.x, mat.diffuseColor.y, mat.diffuseColor.z, mat.alpha); hasRef = mat.refMap != nullptr; hasNor = mat.normalMap != nullptr; diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 2afbc2340..12442bc20 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -196,7 +196,9 @@ protected: float emit; float padding[3]; - MaterialCB(const Material& mat, UINT materialIndex); + MaterialCB() {}; + MaterialCB(const Material& mat, UINT materialIndex) { Create(mat,materialIndex); }; + void Create(const Material& mat, UINT materialIndex); ALIGN_16 };