Commit 40df626e authored by nadro's avatar nadro

- Improved switch between fixed and programmable pipeline materials.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4559 dfc29bdd-3216-0410-991c-e03cc46cb475
parent c2cc0e95
...@@ -70,6 +70,11 @@ COpenGLCgMaterialRenderer::~COpenGLCgMaterialRenderer() ...@@ -70,6 +70,11 @@ COpenGLCgMaterialRenderer::~COpenGLCgMaterialRenderer()
void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services) void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services)
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_ENABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE_TO_DISABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE);
Material = material; Material = material;
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
...@@ -93,18 +98,18 @@ void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const S ...@@ -93,18 +98,18 @@ void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const S
} }
if (BaseMaterial) if (BaseMaterial)
BaseMaterial->OnSetMaterial(material, material, true, this); BaseMaterial->OnSetBaseMaterial(material);
}
if (CallBack) if (CallBack)
CallBack->OnSetMaterial(material); CallBack->OnSetMaterial(material);
}
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
bool COpenGLCgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype) bool COpenGLCgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype)
{ {
Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false, false); Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false);
if (CallBack && (VertexProgram || FragmentProgram || GeometryProgram)) if (CallBack && (VertexProgram || FragmentProgram || GeometryProgram))
CallBack->OnSetConstants(this, UserData); CallBack->OnSetConstants(this, UserData);
......
...@@ -48,6 +48,7 @@ COpenGLDriver::COpenGLDriver(const irr::SIrrlichtCreationParameters& params, ...@@ -48,6 +48,7 @@ COpenGLDriver::COpenGLDriver(const irr::SIrrlichtCreationParameters& params,
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true), CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
AntiAlias(params.AntiAlias), RenderTargetTexture(0), AntiAlias(params.AntiAlias), RenderTargetTexture(0),
CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8), CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8),
FixedPipelineState(EOFPS_ENABLE),
CurrentTarget(ERT_FRAME_BUFFER), Params(params), BridgeCalls(0), CurrentTarget(ERT_FRAME_BUFFER), Params(params), BridgeCalls(0),
HDc(0), Window(static_cast<HWND>(params.WindowId)), Win32Device(device), HDc(0), Window(static_cast<HWND>(params.WindowId)), Win32Device(device),
DeviceType(EIDT_WIN32) DeviceType(EIDT_WIN32)
...@@ -484,6 +485,7 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, ...@@ -484,6 +485,7 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params,
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true), CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
AntiAlias(params.AntiAlias), RenderTargetTexture(0), AntiAlias(params.AntiAlias), RenderTargetTexture(0),
CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8), CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8),
FixedPipelineState(EOFPS_ENABLE),
CurrentTarget(ERT_FRAME_BUFFER), Params(params), BridgeCalls(0), CurrentTarget(ERT_FRAME_BUFFER), Params(params), BridgeCalls(0),
OSXDevice(device), DeviceType(EIDT_OSX) OSXDevice(device), DeviceType(EIDT_OSX)
{ {
...@@ -511,7 +513,8 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, ...@@ -511,7 +513,8 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params,
BridgeCalls(0), CurrentRenderMode(ERM_NONE), ResetRenderStates(true), BridgeCalls(0), CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
Transformation3DChanged(true), AntiAlias(params.AntiAlias), Transformation3DChanged(true), AntiAlias(params.AntiAlias),
RenderTargetTexture(0), CurrentRendertargetSize(0,0), RenderTargetTexture(0), CurrentRendertargetSize(0,0),
ColorFormat(ECF_R8G8B8), CurrentTarget(ERT_FRAME_BUFFER), Params(params), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE),
CurrentTarget(ERT_FRAME_BUFFER), Params(params),
X11Device(device), DeviceType(EIDT_X11) X11Device(device), DeviceType(EIDT_X11)
{ {
#ifdef _DEBUG #ifdef _DEBUG
...@@ -604,7 +607,8 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, ...@@ -604,7 +607,8 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params,
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
Transformation3DChanged(true), AntiAlias(params.AntiAlias), Transformation3DChanged(true), AntiAlias(params.AntiAlias),
RenderTargetTexture(0), CurrentRendertargetSize(0,0), RenderTargetTexture(0), CurrentRendertargetSize(0,0),
ColorFormat(ECF_R8G8B8), CurrentTarget(ERT_FRAME_BUFFER), Params(params), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE),
CurrentTarget(ERT_FRAME_BUFFER), Params(params),
BridgeCalls(0), SDLDevice(device), DeviceType(EIDT_SDL) BridgeCalls(0), SDLDevice(device), DeviceType(EIDT_SDL)
{ {
#ifdef _DEBUG #ifdef _DEBUG
...@@ -2830,16 +2834,16 @@ GLint COpenGLDriver::getTextureWrapMode(const u8 clamp) ...@@ -2830,16 +2834,16 @@ GLint COpenGLDriver::getTextureWrapMode(const u8 clamp)
} }
//! Can be called by an IMaterialRenderer to make its work easier. //! OpenGL version of setBasicRenderStates method.
void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
bool resetAllRenderStates, bool fixedPipeline) bool resetAllRenderStates)
{ {
// Fixed pipeline isn't important for shader based materials // Fixed pipeline isn't important for shader based materials
if(fixedPipeline || resetAllRenderStates) if (resetAllRenderStates || FixedPipelineState == EOFPS_ENABLE || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE)
{ {
// material colors // material colors
if (resetAllRenderStates || if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE ||
lastmaterial.ColorMaterial != material.ColorMaterial) lastmaterial.ColorMaterial != material.ColorMaterial)
{ {
switch (material.ColorMaterial) switch (material.ColorMaterial)
...@@ -2867,7 +2871,7 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -2867,7 +2871,7 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
} }
if (resetAllRenderStates || if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE ||
lastmaterial.AmbientColor != material.AmbientColor || lastmaterial.AmbientColor != material.AmbientColor ||
lastmaterial.DiffuseColor != material.DiffuseColor || lastmaterial.DiffuseColor != material.DiffuseColor ||
lastmaterial.EmissiveColor != material.EmissiveColor || lastmaterial.EmissiveColor != material.EmissiveColor ||
...@@ -2907,7 +2911,7 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -2907,7 +2911,7 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
} }
} }
if (resetAllRenderStates || if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE ||
lastmaterial.SpecularColor != material.SpecularColor || lastmaterial.SpecularColor != material.SpecularColor ||
lastmaterial.Shininess != material.Shininess || lastmaterial.Shininess != material.Shininess ||
lastmaterial.ColorMaterial != material.ColorMaterial) lastmaterial.ColorMaterial != material.ColorMaterial)
...@@ -2937,7 +2941,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -2937,7 +2941,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
} }
// shademode // shademode
if (resetAllRenderStates || (lastmaterial.GouraudShading != material.GouraudShading)) if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE ||
lastmaterial.GouraudShading != material.GouraudShading)
{ {
if (material.GouraudShading) if (material.GouraudShading)
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
...@@ -2946,7 +2951,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -2946,7 +2951,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
} }
// lighting // lighting
if (resetAllRenderStates || (lastmaterial.Lighting != material.Lighting)) if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE ||
lastmaterial.Lighting != material.Lighting)
{ {
if (material.Lighting) if (material.Lighting)
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
...@@ -2955,7 +2961,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -2955,7 +2961,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
} }
// fog // fog
if (resetAllRenderStates || lastmaterial.FogEnable != material.FogEnable) if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE ||
lastmaterial.FogEnable != material.FogEnable)
{ {
if (material.FogEnable) if (material.FogEnable)
glEnable(GL_FOG); glEnable(GL_FOG);
...@@ -2964,16 +2971,32 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -2964,16 +2971,32 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
} }
// normalization // normalization
if (resetAllRenderStates || lastmaterial.NormalizeNormals != material.NormalizeNormals) if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE ||
lastmaterial.NormalizeNormals != material.NormalizeNormals)
{ {
if (material.NormalizeNormals) if (material.NormalizeNormals)
glEnable(GL_NORMALIZE); glEnable(GL_NORMALIZE);
else else
glDisable(GL_NORMALIZE); glDisable(GL_NORMALIZE);
} }
// Set fixed pipeline as active.
FixedPipelineState = EOFPS_ENABLE;
}
else if (FixedPipelineState == EOFPS_ENABLE_TO_DISABLE)
{
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDisable(GL_NORMALIZE);
// Set programmable pipeline as active.
FixedPipelineState = EOFPS_DISABLE;
} }
// fillmode // FixedPipelineState == EOFPS_DISABLE - driver doesn't calls functions related to fixed pipeline.
// fillmode - fixed pipeline call, but it emulate GL_LINES behaviour in rendering, so it stay here.
if (resetAllRenderStates || (lastmaterial.Wireframe != material.Wireframe) || (lastmaterial.PointCloud != material.PointCloud)) if (resetAllRenderStates || (lastmaterial.Wireframe != material.Wireframe) || (lastmaterial.PointCloud != material.PointCloud))
glPolygonMode(GL_FRONT_AND_BACK, material.Wireframe ? GL_LINE : material.PointCloud? GL_POINT : GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, material.Wireframe ? GL_LINE : material.PointCloud? GL_POINT : GL_FILL);
...@@ -3252,7 +3275,7 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -3252,7 +3275,7 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
} }
//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call.
void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates, bool fixedPipeline) void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates)
{ {
// Set textures to TU/TIU and apply filters to them // Set textures to TU/TIU and apply filters to them
...@@ -3260,20 +3283,20 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset ...@@ -3260,20 +3283,20 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset
{ {
const COpenGLTexture* tmpTexture = static_cast<const COpenGLTexture*>(CurrentTexture[i]); const COpenGLTexture* tmpTexture = static_cast<const COpenGLTexture*>(CurrentTexture[i]);
if(fixedPipeline) if(FixedPipelineState == EOFPS_ENABLE || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE)
{ {
if (i>0 && !MultiTextureExtension) if (i>0 && !MultiTextureExtension)
break; break;
if (!CurrentTexture[i]) if (!CurrentTexture[i])
{ {
BridgeCalls->setTexture(i, fixedPipeline); BridgeCalls->setTexture(i, true);
continue; continue;
} }
else else
{ {
BridgeCalls->setTexture(i, fixedPipeline); BridgeCalls->setTexture(i, true);
setTransform ((E_TRANSFORMATION_STATE) (ETS_TEXTURE_0 + i), material.getTextureMatrix(i)); setTransform ((E_TRANSFORMATION_STATE) (ETS_TEXTURE_0 + i), material.getTextureMatrix(i));
} }
...@@ -3282,7 +3305,7 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset ...@@ -3282,7 +3305,7 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset
{ {
if (CurrentTexture[i]) if (CurrentTexture[i])
{ {
BridgeCalls->setTexture(i, fixedPipeline); BridgeCalls->setTexture(i, false);
} }
else else
continue; continue;
...@@ -3409,6 +3432,12 @@ void COpenGLDriver::enableMaterial2D(bool enable) ...@@ -3409,6 +3432,12 @@ void COpenGLDriver::enableMaterial2D(bool enable)
//! sets the needed renderstates //! sets the needed renderstates
void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel)
{ {
// 2d methods uses fixed pipeline
if (FixedPipelineState == COpenGLDriver::EOFPS_DISABLE)
FixedPipelineState = COpenGLDriver::EOFPS_DISABLE_TO_ENABLE;
else
FixedPipelineState = COpenGLDriver::EOFPS_ENABLE;
if (CurrentRenderMode != ERM_2D || Transformation3DChanged) if (CurrentRenderMode != ERM_2D || Transformation3DChanged)
{ {
// unset last 3d material // unset last 3d material
...@@ -3438,7 +3467,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh ...@@ -3438,7 +3467,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
} }
if (!OverrideMaterial2DEnabled) if (!OverrideMaterial2DEnabled)
{ {
setBasicRenderStates(InitMaterial2D, LastMaterial, true, true); setBasicRenderStates(InitMaterial2D, LastMaterial, true);
LastMaterial = InitMaterial2D; LastMaterial = InitMaterial2D;
} }
BridgeCalls->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); BridgeCalls->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
...@@ -3451,7 +3480,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh ...@@ -3451,7 +3480,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
if (OverrideMaterial2DEnabled) if (OverrideMaterial2DEnabled)
{ {
OverrideMaterial2D.Lighting=false; OverrideMaterial2D.Lighting=false;
setBasicRenderStates(OverrideMaterial2D, LastMaterial, false, true); setBasicRenderStates(OverrideMaterial2D, LastMaterial, false);
LastMaterial = OverrideMaterial2D; LastMaterial = OverrideMaterial2D;
} }
...@@ -3473,9 +3502,9 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh ...@@ -3473,9 +3502,9 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
if (texture) if (texture)
{ {
if (OverrideMaterial2DEnabled) if (OverrideMaterial2DEnabled)
setTextureRenderStates(OverrideMaterial2D, false, true); setTextureRenderStates(OverrideMaterial2D, false);
else else
setTextureRenderStates(InitMaterial2D, false, true); setTextureRenderStates(InitMaterial2D, false);
Material.setTexture(0, const_cast<video::ITexture*>(CurrentTexture[0])); Material.setTexture(0, const_cast<video::ITexture*>(CurrentTexture[0]));
setTransform(ETS_TEXTURE_0, core::IdentityMatrix); setTransform(ETS_TEXTURE_0, core::IdentityMatrix);
...@@ -4972,6 +5001,16 @@ GLenum COpenGLDriver::getZBufferBits() const ...@@ -4972,6 +5001,16 @@ GLenum COpenGLDriver::getZBufferBits() const
return bits; return bits;
} }
COpenGLDriver::E_OPENGL_FIXED_PIPELINE_STATE COpenGLDriver::getFixedPipelineState() const
{
return FixedPipelineState;
}
void COpenGLDriver::setFixedPipelineState(COpenGLDriver::E_OPENGL_FIXED_PIPELINE_STATE state)
{
FixedPipelineState = state;
}
const SMaterial& COpenGLDriver::getCurrentMaterial() const const SMaterial& COpenGLDriver::getCurrentMaterial() const
{ {
return Material; return Material;
......
...@@ -41,6 +41,14 @@ namespace video ...@@ -41,6 +41,14 @@ namespace video
friend class COpenGLCallBridge; friend class COpenGLCallBridge;
friend class COpenGLTexture; friend class COpenGLTexture;
public: public:
// Information about state of fixed pipeline activity.
enum E_OPENGL_FIXED_PIPELINE_STATE
{
EOFPS_ENABLE = 0, // fixed pipeline.
EOFPS_DISABLE, // programmable pipeline.
EOFPS_ENABLE_TO_DISABLE, // switch from fixed to programmable pipeline.
EOFPS_DISABLE_TO_ENABLE // switch from programmable to fixed pipeline.
};
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device); COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device);
...@@ -280,16 +288,16 @@ namespace video ...@@ -280,16 +288,16 @@ namespace video
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
bool resetAllRenderstates) _IRR_OVERRIDE_ bool resetAllRenderstates) _IRR_OVERRIDE_
{ {
setBasicRenderStates(material, lastmaterial, resetAllRenderstates, true); setOpenGLBasicRenderStates(material, lastmaterial, resetAllRenderstates);
setTextureRenderStates(material, resetAllRenderstates, true); setTextureRenderStates(material, resetAllRenderstates);
} }
//! Can be called by an IMaterialRenderer to make its work easier. //! OpenGL version of setBasicRenderStates method.
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, void setOpenGLBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
bool resetAllRenderstates, bool fixedPipeline); bool resetAllRenderstates);
//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call.
virtual void setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates, bool fixedPipeline); virtual void setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates);
//! Get a vertex shader constant index. //! Get a vertex shader constant index.
virtual s32 getVertexShaderConstantID(const c8* name) _IRR_OVERRIDE_; virtual s32 getVertexShaderConstantID(const c8* name) _IRR_OVERRIDE_;
...@@ -419,6 +427,12 @@ namespace video ...@@ -419,6 +427,12 @@ namespace video
//! Get ZBuffer bits. //! Get ZBuffer bits.
GLenum getZBufferBits() const; GLenum getZBufferBits() const;
//! Return info about fixed pipeline state.
E_OPENGL_FIXED_PIPELINE_STATE getFixedPipelineState() const;
//! Set info about fixed pipeline state.
void setFixedPipelineState(E_OPENGL_FIXED_PIPELINE_STATE state);
//! Get current material. //! Get current material.
const SMaterial& getCurrentMaterial() const; const SMaterial& getCurrentMaterial() const;
...@@ -583,6 +597,8 @@ namespace video ...@@ -583,6 +597,8 @@ namespace video
//! Color buffer format //! Color buffer format
ECOLOR_FORMAT ColorFormat; ECOLOR_FORMAT ColorFormat;
E_OPENGL_FIXED_PIPELINE_STATE FixedPipelineState;
//! Render target type for render operations //! Render target type for render operations
E_RENDER_TARGET CurrentTarget; E_RENDER_TARGET CurrentTarget;
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) _IRR_OVERRIDE_ virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) _IRR_OVERRIDE_
{ {
Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false, true); Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false);
return true; return true;
} }
...@@ -59,8 +59,13 @@ public: ...@@ -59,8 +59,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(1); Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (resetAllRenderstates || (material.MaterialType != lastMaterial.MaterialType)) if (resetAllRenderstates || (material.MaterialType != lastMaterial.MaterialType))
{ {
...@@ -83,8 +88,13 @@ public: ...@@ -83,8 +88,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(1); Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
// if (material.MaterialType != lastMaterial.MaterialType || // if (material.MaterialType != lastMaterial.MaterialType ||
// material.MaterialTypeParam != lastMaterial.MaterialTypeParam || // material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
...@@ -209,8 +219,13 @@ public: ...@@ -209,8 +219,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(2); Driver->disableTextures(2);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
...@@ -268,8 +283,13 @@ public: ...@@ -268,8 +283,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(1); Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if ((material.MaterialType != lastMaterial.MaterialType) || resetAllRenderstates) if ((material.MaterialType != lastMaterial.MaterialType) || resetAllRenderstates)
{ {
...@@ -314,8 +334,13 @@ public: ...@@ -314,8 +334,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(1); Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
...@@ -383,6 +408,11 @@ public: ...@@ -383,6 +408,11 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(1); Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
...@@ -457,8 +487,13 @@ public: ...@@ -457,8 +487,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(1); Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
...@@ -503,8 +538,13 @@ public: ...@@ -503,8 +538,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(2); Driver->disableTextures(2);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
...@@ -619,8 +659,13 @@ public: ...@@ -619,8 +659,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(2); Driver->disableTextures(2);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
...@@ -668,12 +713,17 @@ public: ...@@ -668,12 +713,17 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(1); Driver->disableTextures(1);
// texture needs to be flipped for OpenGL // texture needs to be flipped for OpenGL
core::matrix4 tmp = Driver->getTransform(ETS_TEXTURE_0); core::matrix4 tmp = Driver->getTransform(ETS_TEXTURE_0);
tmp[5]*=-1; tmp[5]*=-1;
Driver->setTransform(ETS_TEXTURE_0, tmp); Driver->setTransform(ETS_TEXTURE_0, tmp);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
...@@ -704,8 +754,13 @@ public: ...@@ -704,8 +754,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(2); Driver->disableTextures(2);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
...@@ -759,8 +814,13 @@ public: ...@@ -759,8 +814,13 @@ public:
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_ bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{ {
if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE);
Driver->disableTextures(2); Driver->disableTextures(2);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, true); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
......
...@@ -201,7 +201,7 @@ void COpenGLSLMaterialRenderer::init(s32& outMaterialTypeNr, ...@@ -201,7 +201,7 @@ void COpenGLSLMaterialRenderer::init(s32& outMaterialTypeNr,
bool COpenGLSLMaterialRenderer::OnRender(IMaterialRendererServices* service, bool COpenGLSLMaterialRenderer::OnRender(IMaterialRendererServices* service,
E_VERTEX_TYPE vtxtype) E_VERTEX_TYPE vtxtype)
{ {
Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false, false); Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false);
// call callback to set shader constants // call callback to set shader constants
if (CallBack && (Program||Program2)) if (CallBack && (Program||Program2))
...@@ -216,7 +216,10 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material, ...@@ -216,7 +216,10 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material,
bool resetAllRenderstates, bool resetAllRenderstates,
video::IMaterialRendererServices* services) video::IMaterialRendererServices* services)
{ {
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, false); if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_ENABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE_TO_DISABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
...@@ -231,6 +234,8 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material, ...@@ -231,6 +234,8 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material,
if (CallBack) if (CallBack)
CallBack->OnSetMaterial(material); CallBack->OnSetMaterial(material);
} }
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
...@@ -505,7 +510,7 @@ void COpenGLSLMaterialRenderer::setBasicRenderStates(const SMaterial& material, ...@@ -505,7 +510,7 @@ void COpenGLSLMaterialRenderer::setBasicRenderStates(const SMaterial& material,
bool resetAllRenderstates) bool resetAllRenderstates)
{ {
// forward // forward
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, false); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
s32 COpenGLSLMaterialRenderer::getVertexShaderConstantID(const c8* name) s32 COpenGLSLMaterialRenderer::getVertexShaderConstantID(const c8* name)
......
...@@ -120,7 +120,7 @@ void COpenGLShaderMaterialRenderer::init(s32& outMaterialTypeNr, ...@@ -120,7 +120,7 @@ void COpenGLShaderMaterialRenderer::init(s32& outMaterialTypeNr,
bool COpenGLShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) bool COpenGLShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{ {
Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false, false); Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false);
// call callback to set shader constants // call callback to set shader constants
if (CallBack && (VertexShader || PixelShader[0])) if (CallBack && (VertexShader || PixelShader[0]))
...@@ -133,7 +133,10 @@ bool COpenGLShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, ...@@ -133,7 +133,10 @@ bool COpenGLShaderMaterialRenderer::OnRender(IMaterialRendererServices* service,
void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial, void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial,
bool resetAllRenderstates, video::IMaterialRendererServices* services) bool resetAllRenderstates, video::IMaterialRendererServices* services)
{ {
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates, false); if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_ENABLE)
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE_TO_DISABLE);
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{ {
...@@ -181,6 +184,8 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi ...@@ -181,6 +184,8 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi
if (CallBack) if (CallBack)
CallBack->OnSetMaterial(material); CallBack->OnSetMaterial(material);
} }
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment