Code analysis cleanup

- Move modelview/projection matrices to render contexts that use them
- Do not create an unused second light in cmodview
pull/1196/head
Andrew Tribick 2021-11-28 20:21:51 +01:00 committed by ajtribick
parent bcbd538d0a
commit 82ddd20fe2
5 changed files with 44 additions and 42 deletions

View File

@ -100,10 +100,8 @@ void Nebula::render(const Vector3f& /*offset*/,
Matrix4f mv = vecgl::rotate(vecgl::scale(*m.modelview, getRadius()),
getOrientation());
GLSLUnlit_RenderContext rc(renderer, getRadius());
GLSLUnlit_RenderContext rc(renderer, getRadius(), &mv, m.projection);
rc.setPointScale(2.0f * getRadius() / pixelSize * renderer->getScreenDpi() / 96.0f);
rc.setProjectionMatrix(m.projection);
rc.setModelViewMatrix(&mv);
g->render(rc);
renderer->enableBlending();

View File

@ -380,30 +380,22 @@ RenderContext::updateShader(const cmod::VertexDescription& desc, cmod::Primitive
}
}
void
RenderContext::setProjectionMatrix(const Eigen::Matrix4f *m)
{
projectionMatrix = m;
}
void
RenderContext::setModelViewMatrix(const Eigen::Matrix4f *m)
{
modelViewMatrix = m;
}
/***** GLSL render context ******/
GLSL_RenderContext::GLSL_RenderContext(Renderer* renderer,
const LightingState& ls,
float _objRadius,
const Eigen::Quaternionf& orientation) :
const Eigen::Quaternionf& orientation,
const Eigen::Matrix4f* _modelViewMatrix,
const Eigen::Matrix4f* _projectionMatrix) :
RenderContext(renderer),
lightingState(ls),
objRadius(_objRadius),
objScale(Eigen::Vector3f::Constant(_objRadius)),
objOrientation(orientation)
objOrientation(orientation),
modelViewMatrix(_modelViewMatrix),
projectionMatrix(_projectionMatrix)
{
initLightingEnvironment();
}
@ -412,12 +404,16 @@ GLSL_RenderContext::GLSL_RenderContext(Renderer* renderer,
GLSL_RenderContext::GLSL_RenderContext(Renderer* renderer,
const LightingState& ls,
const Eigen::Vector3f& _objScale,
const Eigen::Quaternionf& orientation) :
const Eigen::Quaternionf& orientation,
const Eigen::Matrix4f* _modelViewMatrix,
const Eigen::Matrix4f* _projectionMatrix) :
RenderContext(renderer),
lightingState(ls),
objRadius(_objScale.maxCoeff()),
objScale(_objScale),
objOrientation(orientation)
objOrientation(orientation),
modelViewMatrix(_modelViewMatrix),
projectionMatrix(_projectionMatrix)
{
initLightingEnvironment();
}
@ -781,10 +777,15 @@ GLSL_RenderContext::setShadowMap(GLuint _shadowMap, GLuint _width, const Eigen::
/***** GLSL-Unlit render context ******/
GLSLUnlit_RenderContext::GLSLUnlit_RenderContext(Renderer* renderer, float _objRadius) :
GLSLUnlit_RenderContext::GLSLUnlit_RenderContext(Renderer* renderer,
float _objRadius,
const Eigen::Matrix4f* _modelViewMatrix,
const Eigen::Matrix4f* _projectionMatrix) :
RenderContext(renderer),
blendMode(cmod::BlendMode::InvalidBlend),
objRadius(_objRadius)
objRadius(_objRadius),
modelViewMatrix(_modelViewMatrix),
projectionMatrix(_projectionMatrix)
{
initLightingEnvironment();
}

View File

@ -62,9 +62,6 @@ class RenderContext
void setCameraOrientation(const Eigen::Quaternionf& q);
Eigen::Quaternionf getCameraOrientation() const;
void setModelViewMatrix(const Eigen::Matrix4f *m);
void setProjectionMatrix(const Eigen::Matrix4f *m);
protected:
Renderer* renderer { nullptr };
bool usePointSize{ false };
@ -73,8 +70,6 @@ class RenderContext
bool useColors{ false };
bool useTexCoords{ true };
bool drawLine { false };
const Eigen::Matrix4f *modelViewMatrix;
const Eigen::Matrix4f *projectionMatrix;
private:
const cmod::Material* material{ nullptr };
@ -103,8 +98,18 @@ class GLSL_RenderContext : public RenderContext
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
GLSL_RenderContext(Renderer* r, const LightingState& ls, float _objRadius, const Eigen::Quaternionf& orientation);
GLSL_RenderContext(Renderer* r, const LightingState& ls, const Eigen::Vector3f& _objScale, const Eigen::Quaternionf& orientation);
GLSL_RenderContext(Renderer* r,
const LightingState& ls,
float _objRadius,
const Eigen::Quaternionf& orientation,
const Eigen::Matrix4f *_modelViewMatrix,
const Eigen::Matrix4f *_projectionMatrix);
GLSL_RenderContext(Renderer* r,
const LightingState& ls,
const Eigen::Vector3f& _objScale,
const Eigen::Quaternionf& orientation,
const Eigen::Matrix4f *_modelViewMatrix,
const Eigen::Matrix4f *_projectionMatrix);
~GLSL_RenderContext() override;
void makeCurrent(const cmod::Material&) override;
@ -128,6 +133,8 @@ class GLSL_RenderContext : public RenderContext
float lunarLambert{ 0.0f };
ShaderProperties shaderProps;
const Eigen::Matrix4f *modelViewMatrix;
const Eigen::Matrix4f *projectionMatrix;
const Eigen::Matrix4f *lightMatrix { nullptr };
GLuint shadowMap { 0 };
GLuint shadowMapWidth { 0 };
@ -137,7 +144,10 @@ class GLSL_RenderContext : public RenderContext
class GLSLUnlit_RenderContext : public RenderContext
{
public:
GLSLUnlit_RenderContext(Renderer* r, float _objRadius);
GLSLUnlit_RenderContext(Renderer* r,
float _objRadius,
const Eigen::Matrix4f *_modelViewMatrix,
const Eigen::Matrix4f *_projectionMatrix);
~GLSLUnlit_RenderContext() override;
void makeCurrent(const cmod::Material&) override;
@ -150,4 +160,7 @@ class GLSLUnlit_RenderContext : public RenderContext
float objRadius;
ShaderProperties shaderProps;
const Eigen::Matrix4f *modelViewMatrix;
const Eigen::Matrix4f *projectionMatrix;
};

View File

@ -442,9 +442,7 @@ void renderGeometry_GLSL(Geometry* geometry,
glDepthRange(range[0], range[1]);
}
GLSL_RenderContext rc(renderer, ls, geometryScale, planetOrientation);
rc.setModelViewMatrix(m.modelview);
rc.setProjectionMatrix(m.projection);
GLSL_RenderContext rc(renderer, ls, geometryScale, planetOrientation, m.modelview, m.projection);
if ((renderFlags & Renderer::ShowAtmospheres) != 0)
{
@ -497,10 +495,7 @@ void renderGeometry_GLSL_Unlit(Geometry* geometry,
const Matrices &m,
Renderer* renderer)
{
GLSLUnlit_RenderContext rc(renderer, geometryScale);
rc.setModelViewMatrix(m.modelview);
rc.setProjectionMatrix(m.projection);
GLSLUnlit_RenderContext rc(renderer, geometryScale, m.modelview, m.projection);
rc.setPointScale(ri.pointScale);
// Handle material override; a texture specified in an ssc file will

View File

@ -1243,12 +1243,7 @@ ModelViewWidget::setupDefaultLightSources()
light1.intensity = 1.0f;
light1.direction = Eigen::Vector3d(1.0, 1.0, 5.0).normalized();
LightSource light2;
light2.color = Eigen::Vector3f(1.0f, 1.0f, 1.0f);
light2.intensity = 1.0f;
light2.direction = Eigen::Vector3d(3.0, -3.0, -1.0).normalized();
m_lightSources << light1;// << light2;
m_lightSources << light1;
}