Replace raw pointers in IGLShadowMapRenderer
etc. with references
This commit is contained in:
parent
b1b07cf579
commit
bc08e23d80
@ -29,14 +29,14 @@
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
|
||||
GLBasicShadowMapRenderer::GLBasicShadowMapRenderer(GLRenderer *r)
|
||||
: IGLShadowMapRenderer(r), device(r->GetGLDevice()) {
|
||||
GLBasicShadowMapRenderer::GLBasicShadowMapRenderer(GLRenderer &r)
|
||||
: IGLShadowMapRenderer(r), device(r.GetGLDevice()) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
textureSize = r->GetSettings().r_shadowMapSize;
|
||||
textureSize = r.GetSettings().r_shadowMapSize;
|
||||
if ((int)textureSize > 4096) {
|
||||
SPLog("r_shadowMapSize is too large; changed to 4096");
|
||||
r->GetSettings().r_shadowMapSize = textureSize = 4096;
|
||||
r.GetSettings().r_shadowMapSize = textureSize = 4096;
|
||||
}
|
||||
|
||||
colorTexture = device.GenTexture();
|
||||
@ -140,7 +140,7 @@ namespace spades {
|
||||
up = Vector3::Cross(lightDir, side).Normalize();
|
||||
|
||||
// build frustrum
|
||||
client::SceneDefinition def = GetRenderer()->GetSceneDef();
|
||||
client::SceneDefinition def = GetRenderer().GetSceneDef();
|
||||
Vector3 frustrum[8];
|
||||
float tanX = tanf(def.fovX * .5f);
|
||||
float tanY = tanf(def.fovY * .5f);
|
||||
@ -224,13 +224,13 @@ namespace spades {
|
||||
|
||||
IGLDevice::Integer lastFb = device.GetInteger(IGLDevice::FramebufferBinding);
|
||||
|
||||
// client::SceneDefinition def = GetRenderer()->GetSceneDef();
|
||||
// client::SceneDefinition def = GetRenderer().GetSceneDef();
|
||||
|
||||
float nearDist = 0.f;
|
||||
|
||||
for (int i = 0; i < NumSlices; i++) {
|
||||
|
||||
GLProfiler::Context profiler(GetRenderer()->GetGLProfiler(), "Slice %d / %d", i + 1,
|
||||
GLProfiler::Context profiler(GetRenderer().GetGLProfiler(), "Slice %d / %d", i + 1,
|
||||
(int)NumSlices);
|
||||
|
||||
float farDist = 0.0;
|
||||
|
@ -49,7 +49,7 @@ namespace spades {
|
||||
void BuildMatrix(float near, float far);
|
||||
|
||||
public:
|
||||
GLBasicShadowMapRenderer(GLRenderer *);
|
||||
GLBasicShadowMapRenderer(GLRenderer &);
|
||||
~GLBasicShadowMapRenderer();
|
||||
void Render() override;
|
||||
|
||||
|
@ -135,7 +135,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
SPLog("GLRenderer initializing for 3D rendering");
|
||||
shadowMapRenderer = GLShadowMapShader::CreateShadowMapRenderer(this);
|
||||
shadowMapRenderer = GLShadowMapShader::CreateShadowMapRenderer(*this);
|
||||
modelManager = new GLModelManager(this);
|
||||
if ((int)settings.r_softParticles >= 2)
|
||||
spriteRenderer = new GLSoftLitSpriteRenderer(this);
|
||||
|
@ -49,9 +49,9 @@ namespace spades {
|
||||
}
|
||||
|
||||
IGLShadowMapRenderer *
|
||||
GLShadowMapShader::CreateShadowMapRenderer(spades::draw::GLRenderer *r) {
|
||||
GLShadowMapShader::CreateShadowMapRenderer(GLRenderer &r) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
auto &settings = r->GetSettings();
|
||||
auto &settings = r.GetSettings();
|
||||
if (!settings.r_modelShadows)
|
||||
return NULL;
|
||||
if (settings.r_sparseShadowMaps)
|
||||
|
@ -39,7 +39,7 @@ namespace spades {
|
||||
|
||||
static std::vector<GLShader *> RegisterShader(GLProgramManager *);
|
||||
|
||||
static IGLShadowMapRenderer *CreateShadowMapRenderer(GLRenderer *);
|
||||
static IGLShadowMapRenderer *CreateShadowMapRenderer(GLRenderer &);
|
||||
|
||||
/** setups shadow map shader.
|
||||
* note that this function sets the current active texture
|
||||
|
@ -19,21 +19,20 @@
|
||||
*/
|
||||
|
||||
#include "GLSparseShadowMapRenderer.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
#include <Core/Settings.h>
|
||||
#include "GLModel.h"
|
||||
#include "GLModelRenderer.h"
|
||||
#include "GLProfiler.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
#include <Core/Settings.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
|
||||
GLSparseShadowMapRenderer::GLSparseShadowMapRenderer(GLRenderer *r)
|
||||
: IGLShadowMapRenderer(r), device(r->GetGLDevice()), settings(r->GetSettings()) {
|
||||
GLSparseShadowMapRenderer::GLSparseShadowMapRenderer(GLRenderer &r)
|
||||
: IGLShadowMapRenderer(r), device(r.GetGLDevice()), settings(r.GetSettings()) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
textureSize = settings.r_shadowMapSize;
|
||||
@ -51,49 +50,49 @@ namespace spades {
|
||||
colorTexture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, colorTexture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGB, textureSize, textureSize, 0,
|
||||
IGLDevice::RGB, IGLDevice::UnsignedByte, NULL);
|
||||
IGLDevice::RGB, IGLDevice::UnsignedByte, NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
texture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, texture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24, textureSize,
|
||||
textureSize, 0, IGLDevice::DepthComponent, IGLDevice::UnsignedInt,
|
||||
NULL);
|
||||
textureSize, 0, IGLDevice::DepthComponent, IGLDevice::UnsignedInt,
|
||||
NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
pagetableTexture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, pagetableTexture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, Tiles, Tiles, 0,
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte, NULL);
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte, NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
framebuffer = device.GenFramebuffer();
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, framebuffer);
|
||||
device.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, colorTexture, 0);
|
||||
IGLDevice::Texture2D, colorTexture, 0);
|
||||
device.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, texture, 0);
|
||||
IGLDevice::Texture2D, texture, 0);
|
||||
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
}
|
||||
@ -159,7 +158,7 @@ namespace spades {
|
||||
up = Vector3::Cross(lightDir, side).Normalize();
|
||||
|
||||
// build frustrum
|
||||
client::SceneDefinition def = GetRenderer()->GetSceneDef();
|
||||
client::SceneDefinition def = GetRenderer().GetSceneDef();
|
||||
Vector3 frustrum[8];
|
||||
float tanX = tanf(def.fovX * .5f);
|
||||
float tanY = tanf(def.fovY * .5f);
|
||||
@ -243,7 +242,7 @@ namespace spades {
|
||||
|
||||
IGLDevice::Integer lastFb = device.GetInteger(IGLDevice::FramebufferBinding);
|
||||
|
||||
// client::SceneDefinition def = GetRenderer()->GetSceneDef();
|
||||
// client::SceneDefinition def = GetRenderer().GetSceneDef();
|
||||
|
||||
float nearDist = 0.f;
|
||||
float farDist = 150.f;
|
||||
@ -270,7 +269,7 @@ namespace spades {
|
||||
static const size_t GroupNodeFlag = NoNode ^ (NoNode >> 1);
|
||||
|
||||
struct GLSparseShadowMapRenderer::Internal {
|
||||
GLSparseShadowMapRenderer *renderer;
|
||||
GLSparseShadowMapRenderer &renderer;
|
||||
Vector3 cameraShadowCoord;
|
||||
|
||||
typedef int LodUnit;
|
||||
@ -476,12 +475,13 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
Internal(GLSparseShadowMapRenderer *r) : renderer(r) {
|
||||
Internal(GLSparseShadowMapRenderer &r) : renderer(r) {
|
||||
|
||||
GLProfiler::Context profiler(r->GetRenderer()->GetGLProfiler(), "Sparse Page Table Generation");
|
||||
GLProfiler::Context profiler(r.GetRenderer().GetGLProfiler(),
|
||||
"Sparse Page Table Generation");
|
||||
|
||||
cameraShadowCoord = r->GetRenderer()->GetSceneDef().viewOrigin;
|
||||
cameraShadowCoord = (r->matrix * cameraShadowCoord).GetXYZ();
|
||||
cameraShadowCoord = r.GetRenderer().GetSceneDef().viewOrigin;
|
||||
cameraShadowCoord = (r.matrix * cameraShadowCoord).GetXYZ();
|
||||
|
||||
// clear group maps
|
||||
for (size_t x = 0; x < Tiles; x++)
|
||||
@ -489,7 +489,7 @@ namespace spades {
|
||||
groupMap[x][y] = NoGroup;
|
||||
|
||||
const std::vector<GLModelRenderer::RenderModel> &rmodels =
|
||||
renderer->GetRenderer()->GetModelRenderer()->models;
|
||||
renderer.GetRenderer().GetModelRenderer()->models;
|
||||
allInstances.reserve(256);
|
||||
groups.reserve(64);
|
||||
nodes.reserve(256);
|
||||
@ -509,7 +509,7 @@ namespace spades {
|
||||
|
||||
OBB3 instWorldBoundsOBB = inst.param->matrix * modelBounds;
|
||||
// w should be 1, so this should wor
|
||||
OBB3 instBoundsOBB = r->matrix * instWorldBoundsOBB;
|
||||
OBB3 instBoundsOBB = r.matrix * instWorldBoundsOBB;
|
||||
AABB3 instBounds = instBoundsOBB.GetBoundingAABB();
|
||||
|
||||
// frustrum(?) cull
|
||||
@ -562,7 +562,7 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
mapSize = r->settings.r_shadowMapSize;
|
||||
mapSize = r.settings.r_shadowMapSize;
|
||||
}
|
||||
|
||||
bool AddGroupToNode(size_t &nodeRef, int nx, int ny, int nw, int nh, size_t gId) {
|
||||
@ -572,8 +572,8 @@ namespace spades {
|
||||
int w = g.tile2.x - g.tile1.x;
|
||||
int h = g.tile2.y - g.tile1.y;
|
||||
int lod = g.lod;
|
||||
int minLod = renderer->minLod;
|
||||
int maxLod = renderer->maxLod;
|
||||
int minLod = renderer.minLod;
|
||||
int maxLod = renderer.maxLod;
|
||||
lod += lodBias;
|
||||
if (lod < minLod)
|
||||
lod = minLod;
|
||||
@ -663,7 +663,8 @@ namespace spades {
|
||||
if (groups.empty())
|
||||
return;
|
||||
|
||||
GLProfiler::Context profiler(renderer->GetRenderer()->GetGLProfiler(), "Pack [%d group(s)]", (int)groups.size());
|
||||
GLProfiler::Context profiler(renderer.GetRenderer().GetGLProfiler(),
|
||||
"Pack [%d group(s)]", (int)groups.size());
|
||||
|
||||
lodBias = 100;
|
||||
if (TryPack()) {
|
||||
@ -708,11 +709,12 @@ namespace spades {
|
||||
};
|
||||
|
||||
void GLSparseShadowMapRenderer::RenderShadowMapPass() {
|
||||
Internal itnl(this);
|
||||
Internal itnl(*this);
|
||||
itnl.Pack();
|
||||
|
||||
{
|
||||
GLProfiler::Context profiler(GetRenderer()->GetGLProfiler(), "Page Table Generation");
|
||||
GLProfiler::Context profiler(GetRenderer().GetGLProfiler(),
|
||||
"Page Table Generation");
|
||||
for (int x = 0; x < Tiles; x++) {
|
||||
for (int y = 0; y < Tiles; y++) {
|
||||
size_t val = itnl.groupMap[x][y];
|
||||
@ -749,15 +751,16 @@ namespace spades {
|
||||
}
|
||||
|
||||
{
|
||||
GLProfiler::Context profiler(GetRenderer()->GetGLProfiler(), "Page Table Upload");
|
||||
GLProfiler::Context profiler(GetRenderer().GetGLProfiler(), "Page Table Upload");
|
||||
device.BindTexture(IGLDevice::Texture2D, pagetableTexture);
|
||||
device.TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, Tiles, Tiles, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, pagetable);
|
||||
IGLDevice::UnsignedByte, pagetable);
|
||||
}
|
||||
|
||||
Matrix4 baseMatrix = matrix;
|
||||
{
|
||||
GLProfiler::Context profiler(GetRenderer()->GetGLProfiler(), "Shadow Maps [%d group(s)]", (int)itnl.groups.size());
|
||||
GLProfiler::Context profiler(GetRenderer().GetGLProfiler(),
|
||||
"Shadow Maps [%d group(s)]", (int)itnl.groups.size());
|
||||
ModelRenderer mrend;
|
||||
for (size_t i = 0; i < itnl.groups.size(); i++) {
|
||||
Internal::Group &g = itnl.groups[i];
|
||||
@ -818,5 +821,5 @@ namespace spades {
|
||||
|
||||
return xx < (1.f + rx) && yy < (1.f + ry);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -63,7 +63,7 @@ namespace spades {
|
||||
void RenderShadowMapPass() override;
|
||||
|
||||
public:
|
||||
GLSparseShadowMapRenderer(GLRenderer *);
|
||||
GLSparseShadowMapRenderer(GLRenderer &);
|
||||
~GLSparseShadowMapRenderer();
|
||||
void Render() override;
|
||||
|
||||
|
@ -25,10 +25,10 @@
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
IGLShadowMapRenderer::IGLShadowMapRenderer(GLRenderer *renderer) : renderer(renderer) {}
|
||||
IGLShadowMapRenderer::IGLShadowMapRenderer(GLRenderer &renderer) : renderer(renderer) {}
|
||||
void IGLShadowMapRenderer::RenderShadowMapPass() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
renderer->modelRenderer->RenderShadowMapPass();
|
||||
renderer.modelRenderer->RenderShadowMapPass();
|
||||
}
|
||||
}
|
||||
}
|
@ -34,16 +34,16 @@ namespace spades {
|
||||
};
|
||||
|
||||
class IGLShadowMapRenderer {
|
||||
GLRenderer *renderer;
|
||||
GLRenderer &renderer;
|
||||
|
||||
protected:
|
||||
virtual void RenderShadowMapPass();
|
||||
|
||||
public:
|
||||
IGLShadowMapRenderer(GLRenderer *);
|
||||
IGLShadowMapRenderer(GLRenderer &);
|
||||
virtual ~IGLShadowMapRenderer() {}
|
||||
|
||||
GLRenderer *GetRenderer() { return renderer; }
|
||||
GLRenderer &GetRenderer() { return renderer; }
|
||||
|
||||
virtual void Render() = 0;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user