Added more control of face culling

This commit is contained in:
Magne Sjaastad 2013-12-18 08:57:10 +01:00
parent 473a49f83d
commit a617c4a430
3 changed files with 45 additions and 13 deletions

View File

@ -157,7 +157,7 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot*
caf::PolygonOffset polygonOffset = caf::PO_1;
caf::ScalarMapperEffectGenerator scalarEffgen(mapper, polygonOffset);
scalarEffgen.setCullBackfaces(true);
scalarEffgen.setCullBackfaces(caf::FC_BACK);
scalarEffgen.setOpacityLevel(m_opacityLevel);
@ -210,7 +210,7 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot*
caf::PolygonOffset polygonOffset = caf::PO_1;
caf::ScalarMapperEffectGenerator scalarEffgen(mapper, polygonOffset);
scalarEffgen.setCullBackfaces(true);
scalarEffgen.setCullBackfaces(caf::FC_BACK);
scalarEffgen.setOpacityLevel(m_opacityLevel);

View File

@ -238,7 +238,7 @@ SurfaceEffectGenerator::SurfaceEffectGenerator(const cvf::Color4f& color, Polygo
{
m_color = color;
m_polygonOffset = polygonOffset;
m_cullBackfaces = false;
m_cullBackfaces = FC_NONE;
}
//--------------------------------------------------------------------------------------------------
@ -248,7 +248,7 @@ SurfaceEffectGenerator::SurfaceEffectGenerator(const cvf::Color3f& color, Polygo
{
m_color = cvf::Color4f(color, 1.0f);
m_polygonOffset = polygonOffset;
m_cullBackfaces = false;
m_cullBackfaces = FC_NONE;
}
@ -313,10 +313,22 @@ void SurfaceEffectGenerator::updateCommonEffect(cvf::Effect* effect) const
}
// Backface culling
if (m_cullBackfaces)
if (m_cullBackfaces != FC_NONE)
{
cvf::ref<cvf::RenderStateCullFace> faceCulling = new cvf::RenderStateCullFace;
if (m_cullBackfaces == FC_BACK)
{
faceCulling->setMode(cvf::RenderStateCullFace::BACK);
}
else if (m_cullBackfaces == FC_FRONT)
{
faceCulling->setMode(cvf::RenderStateCullFace::FRONT);
}
else if (m_cullBackfaces == FC_FRONT_AND_BACK)
{
faceCulling->setMode(cvf::RenderStateCullFace::FRONT_AND_BACK);
}
effect->setRenderState(faceCulling.p());
}
}
@ -371,7 +383,7 @@ ScalarMapperEffectGenerator::ScalarMapperEffectGenerator(const cvf::ScalarMapper
m_scalarMapper = scalarMapper;
m_polygonOffset = polygonOffset;
m_opacityLevel = 1.0f;
m_cullBackfaces = false;
m_cullBackfaces = FC_NONE;
}
//--------------------------------------------------------------------------------------------------
@ -469,10 +481,22 @@ void ScalarMapperEffectGenerator::updateCommonEffect(cvf::Effect* effect) const
}
// Backface culling
if (m_cullBackfaces)
if (m_cullBackfaces != FC_NONE)
{
cvf::ref<cvf::RenderStateCullFace> faceCulling = new cvf::RenderStateCullFace;
if (m_cullBackfaces == FC_BACK)
{
faceCulling->setMode(cvf::RenderStateCullFace::BACK);
}
else if (m_cullBackfaces == FC_FRONT)
{
faceCulling->setMode(cvf::RenderStateCullFace::FRONT);
}
else if (m_cullBackfaces == FC_FRONT_AND_BACK)
{
faceCulling->setMode(cvf::RenderStateCullFace::FRONT_AND_BACK);
}
effect->setRenderState(faceCulling.p());
}
}

View File

@ -64,6 +64,14 @@ enum PolygonOffset
PO_3 = 3 // Even more offset
};
// Enumerates face culling
enum FaceCulling
{
FC_BACK,
FC_FRONT,
FC_FRONT_AND_BACK,
FC_NONE
};
//==================================================================================================
@ -116,7 +124,7 @@ public:
SurfaceEffectGenerator(const cvf::Color4f& color, PolygonOffset polygonOffset);
SurfaceEffectGenerator(const cvf::Color3f& color, PolygonOffset polygonOffset);
void setCullBackfaces(bool cullBackFaces) { m_cullBackfaces = cullBackFaces; }
void setCullBackfaces(FaceCulling cullBackFaces) { m_cullBackfaces = cullBackFaces; }
protected:
virtual bool isEqual(const EffectGenerator* other) const;
@ -131,7 +139,7 @@ private:
private:
cvf::Color4f m_color;
PolygonOffset m_polygonOffset;
bool m_cullBackfaces;
FaceCulling m_cullBackfaces;
};
@ -148,7 +156,7 @@ public:
void setOpacityLevel(float opacity) { m_opacityLevel = cvf::Math::clamp(opacity, 0.0f , 1.0f ); }
void setUndefinedColor(cvf::Color3f color) { m_undefinedColor = color; }
void setCullBackfaces(bool cullBackFaces) { m_cullBackfaces = cullBackFaces; }
void setCullBackfaces(FaceCulling cullBackFaces) { m_cullBackfaces = cullBackFaces; }
public:
static cvf::ref<cvf::TextureImage> addAlphaAndUndefStripes(const cvf::TextureImage* texImg, const cvf::Color3f& undefScalarColor, float opacityLevel);
static bool isImagesEqual(const cvf::TextureImage* texImg1, const cvf::TextureImage* texImg2);
@ -169,7 +177,7 @@ private:
PolygonOffset m_polygonOffset;
float m_opacityLevel;
cvf::Color3f m_undefinedColor;
bool m_cullBackfaces;
FaceCulling m_cullBackfaces;
};