public void Bind(GalPipelineState New) { BindConstBuffers(New); BindVertexLayout(New); if (New.FramebufferSrgb != Old.FramebufferSrgb) { Enable(EnableCap.FramebufferSrgb, New.FramebufferSrgb); RenderTarget.FramebufferSrgb = New.FramebufferSrgb; } if (New.FlipX != Old.FlipX || New.FlipY != Old.FlipY || New.Instance != Old.Instance) { Shader.SetExtraData(New.FlipX, New.FlipY, New.Instance); } //Note: Uncomment SetFrontFace and SetCullFace when flipping issues are solved //if (New.FrontFace != Old.FrontFace) //{ // GL.FrontFace(OGLEnumConverter.GetFrontFace(New.FrontFace)); //} //if (New.CullFaceEnabled != Old.CullFaceEnabled) //{ // Enable(EnableCap.CullFace, New.CullFaceEnabled); //} //if (New.CullFaceEnabled) //{ // if (New.CullFace != Old.CullFace) // { // GL.CullFace(OGLEnumConverter.GetCullFace(New.CullFace)); // } //} if (New.DepthTestEnabled != Old.DepthTestEnabled) { Enable(EnableCap.DepthTest, New.DepthTestEnabled); } if (New.DepthWriteEnabled != Old.DepthWriteEnabled) { GL.DepthMask(New.DepthWriteEnabled); } if (New.DepthTestEnabled) { if (New.DepthFunc != Old.DepthFunc) { GL.DepthFunc(OGLEnumConverter.GetDepthFunc(New.DepthFunc)); } } if (New.DepthRangeNear != Old.DepthRangeNear || New.DepthRangeFar != Old.DepthRangeFar) { GL.DepthRange(New.DepthRangeNear, New.DepthRangeFar); } if (New.StencilTestEnabled != Old.StencilTestEnabled) { Enable(EnableCap.StencilTest, New.StencilTestEnabled); } if (New.StencilTwoSideEnabled != Old.StencilTwoSideEnabled) { Enable((EnableCap)All.StencilTestTwoSideExt, New.StencilTwoSideEnabled); } if (New.StencilTestEnabled) { if (New.StencilBackFuncFunc != Old.StencilBackFuncFunc || New.StencilBackFuncRef != Old.StencilBackFuncRef || New.StencilBackFuncMask != Old.StencilBackFuncMask) { GL.StencilFuncSeparate( StencilFace.Back, OGLEnumConverter.GetStencilFunc(New.StencilBackFuncFunc), New.StencilBackFuncRef, New.StencilBackFuncMask); } if (New.StencilBackOpFail != Old.StencilBackOpFail || New.StencilBackOpZFail != Old.StencilBackOpZFail || New.StencilBackOpZPass != Old.StencilBackOpZPass) { GL.StencilOpSeparate( StencilFace.Back, OGLEnumConverter.GetStencilOp(New.StencilBackOpFail), OGLEnumConverter.GetStencilOp(New.StencilBackOpZFail), OGLEnumConverter.GetStencilOp(New.StencilBackOpZPass)); } if (New.StencilBackMask != Old.StencilBackMask) { GL.StencilMaskSeparate(StencilFace.Back, New.StencilBackMask); } if (New.StencilFrontFuncFunc != Old.StencilFrontFuncFunc || New.StencilFrontFuncRef != Old.StencilFrontFuncRef || New.StencilFrontFuncMask != Old.StencilFrontFuncMask) { GL.StencilFuncSeparate( StencilFace.Front, OGLEnumConverter.GetStencilFunc(New.StencilFrontFuncFunc), New.StencilFrontFuncRef, New.StencilFrontFuncMask); } if (New.StencilFrontOpFail != Old.StencilFrontOpFail || New.StencilFrontOpZFail != Old.StencilFrontOpZFail || New.StencilFrontOpZPass != Old.StencilFrontOpZPass) { GL.StencilOpSeparate( StencilFace.Front, OGLEnumConverter.GetStencilOp(New.StencilFrontOpFail), OGLEnumConverter.GetStencilOp(New.StencilFrontOpZFail), OGLEnumConverter.GetStencilOp(New.StencilFrontOpZPass)); } if (New.StencilFrontMask != Old.StencilFrontMask) { GL.StencilMaskSeparate(StencilFace.Front, New.StencilFrontMask); } } // Scissor Test bool forceUpdate; for (int Index = 0; Index < New.ScissorTestCount; Index++) { forceUpdate = false; if (New.ScissorTestEnabled[Index]) { // If there is only 1 scissor test, geometry shaders are disabled so the scissor test applies to all viewports if (New.ScissorTestCount == 1) { GL.Enable(EnableCap.ScissorTest); } else { GL.Enable(IndexedEnableCap.ScissorTest, Index); } forceUpdate = true; } else { GL.Disable(IndexedEnableCap.ScissorTest, Index); } if (New.ScissorTestEnabled[Index] && (New.ScissorTestX[Index] != Old.ScissorTestX[Index] || New.ScissorTestY[Index] != Old.ScissorTestY[Index] || New.ScissorTestWidth[Index] != Old.ScissorTestWidth[Index] || New.ScissorTestHeight[Index] != Old.ScissorTestHeight[Index] || forceUpdate)) // Force update intentionally last to reduce if comparisons { // If there is only 1 scissor test geometry shaders are disables so the scissor test applies to all viewports if (New.ScissorTestCount == 1) { GL.Scissor(New.ScissorTestX[Index], New.ScissorTestY[Index], New.ScissorTestWidth[Index], New.ScissorTestHeight[Index]); } else { GL.ScissorIndexed(Index, New.ScissorTestX[Index], New.ScissorTestY[Index], New.ScissorTestWidth[Index], New.ScissorTestHeight[Index]); } } } if (New.BlendIndependent) { for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++) { SetBlendState(Index, New.Blends[Index], Old.Blends[Index]); } } else { if (New.BlendIndependent != Old.BlendIndependent) { SetAllBlendState(New.Blends[0]); } else { SetBlendState(New.Blends[0], Old.Blends[0]); } } if (New.ColorMaskCommon) { if (New.ColorMaskCommon != Old.ColorMaskCommon || !New.ColorMasks[0].Equals(Old.ColorMasks[0])) { GL.ColorMask( New.ColorMasks[0].Red, New.ColorMasks[0].Green, New.ColorMasks[0].Blue, New.ColorMasks[0].Alpha); } } else { for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++) { if (!New.ColorMasks[Index].Equals(Old.ColorMasks[Index])) { GL.ColorMask( Index, New.ColorMasks[Index].Red, New.ColorMasks[Index].Green, New.ColorMasks[Index].Blue, New.ColorMasks[Index].Alpha); } } } if (New.PrimitiveRestartEnabled != Old.PrimitiveRestartEnabled) { Enable(EnableCap.PrimitiveRestart, New.PrimitiveRestartEnabled); } if (New.PrimitiveRestartEnabled) { if (New.PrimitiveRestartIndex != Old.PrimitiveRestartIndex) { GL.PrimitiveRestartIndex(New.PrimitiveRestartIndex); } } Old = New; }
public void Bind(GalPipelineState New) { BindConstBuffers(New); BindVertexLayout(New); if (New.FramebufferSrgb != Old.FramebufferSrgb) { Enable(EnableCap.FramebufferSrgb, New.FramebufferSrgb); } if (New.FlipX != Old.FlipX || New.FlipY != Old.FlipY || New.Instance != Old.Instance) { Shader.SetExtraData(New.FlipX, New.FlipY, New.Instance); } //Note: Uncomment SetFrontFace and SetCullFace when flipping issues are solved //if (New.FrontFace != Old.FrontFace) //{ // GL.FrontFace(OGLEnumConverter.GetFrontFace(New.FrontFace)); //} //if (New.CullFaceEnabled != Old.CullFaceEnabled) //{ // Enable(EnableCap.CullFace, New.CullFaceEnabled); //} //if (New.CullFaceEnabled) //{ // if (New.CullFace != Old.CullFace) // { // GL.CullFace(OGLEnumConverter.GetCullFace(New.CullFace)); // } //} if (New.DepthTestEnabled != Old.DepthTestEnabled) { Enable(EnableCap.DepthTest, New.DepthTestEnabled); } if (New.DepthWriteEnabled != Old.DepthWriteEnabled) { GL.DepthMask(New.DepthWriteEnabled); } if (New.DepthTestEnabled) { if (New.DepthFunc != Old.DepthFunc) { GL.DepthFunc(OGLEnumConverter.GetDepthFunc(New.DepthFunc)); } } if (New.DepthRangeNear != Old.DepthRangeNear || New.DepthRangeFar != Old.DepthRangeFar) { GL.DepthRange(New.DepthRangeNear, New.DepthRangeFar); } if (New.StencilTestEnabled != Old.StencilTestEnabled) { Enable(EnableCap.StencilTest, New.StencilTestEnabled); } if (New.StencilTwoSideEnabled != Old.StencilTwoSideEnabled) { Enable((EnableCap)All.StencilTestTwoSideExt, New.StencilTwoSideEnabled); } if (New.StencilTestEnabled) { if (New.StencilBackFuncFunc != Old.StencilBackFuncFunc || New.StencilBackFuncRef != Old.StencilBackFuncRef || New.StencilBackFuncMask != Old.StencilBackFuncMask) { GL.StencilFuncSeparate( StencilFace.Back, OGLEnumConverter.GetStencilFunc(New.StencilBackFuncFunc), New.StencilBackFuncRef, New.StencilBackFuncMask); } if (New.StencilBackOpFail != Old.StencilBackOpFail || New.StencilBackOpZFail != Old.StencilBackOpZFail || New.StencilBackOpZPass != Old.StencilBackOpZPass) { GL.StencilOpSeparate( StencilFace.Back, OGLEnumConverter.GetStencilOp(New.StencilBackOpFail), OGLEnumConverter.GetStencilOp(New.StencilBackOpZFail), OGLEnumConverter.GetStencilOp(New.StencilBackOpZPass)); } if (New.StencilBackMask != Old.StencilBackMask) { GL.StencilMaskSeparate(StencilFace.Back, New.StencilBackMask); } if (New.StencilFrontFuncFunc != Old.StencilFrontFuncFunc || New.StencilFrontFuncRef != Old.StencilFrontFuncRef || New.StencilFrontFuncMask != Old.StencilFrontFuncMask) { GL.StencilFuncSeparate( StencilFace.Front, OGLEnumConverter.GetStencilFunc(New.StencilFrontFuncFunc), New.StencilFrontFuncRef, New.StencilFrontFuncMask); } if (New.StencilFrontOpFail != Old.StencilFrontOpFail || New.StencilFrontOpZFail != Old.StencilFrontOpZFail || New.StencilFrontOpZPass != Old.StencilFrontOpZPass) { GL.StencilOpSeparate( StencilFace.Front, OGLEnumConverter.GetStencilOp(New.StencilFrontOpFail), OGLEnumConverter.GetStencilOp(New.StencilFrontOpZFail), OGLEnumConverter.GetStencilOp(New.StencilFrontOpZPass)); } if (New.StencilFrontMask != Old.StencilFrontMask) { GL.StencilMaskSeparate(StencilFace.Front, New.StencilFrontMask); } } if (New.BlendIndependent) { for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++) { SetBlendState(Index, New.Blends[Index], Old.Blends[Index]); } } else { if (New.BlendIndependent != Old.BlendIndependent) { SetAllBlendState(New.Blends[0]); } else { SetBlendState(New.Blends[0], Old.Blends[0]); } } if (New.ColorMaskCommon) { if (New.ColorMaskCommon != Old.ColorMaskCommon || !New.ColorMasks[0].Equals(Old.ColorMasks[0])) { GL.ColorMask( New.ColorMasks[0].Red, New.ColorMasks[0].Green, New.ColorMasks[0].Blue, New.ColorMasks[0].Alpha); } } else { for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++) { if (!New.ColorMasks[Index].Equals(Old.ColorMasks[Index])) { GL.ColorMask( Index, New.ColorMasks[Index].Red, New.ColorMasks[Index].Green, New.ColorMasks[Index].Blue, New.ColorMasks[Index].Alpha); } } } if (New.PrimitiveRestartEnabled != Old.PrimitiveRestartEnabled) { Enable(EnableCap.PrimitiveRestart, New.PrimitiveRestartEnabled); } if (New.PrimitiveRestartEnabled) { if (New.PrimitiveRestartIndex != Old.PrimitiveRestartIndex) { GL.PrimitiveRestartIndex(New.PrimitiveRestartIndex); } } Old = New; }
public void Bind(GalPipelineState New) { BindConstBuffers(New); BindVertexLayout(New); if (New.FlipX != Old.FlipX || New.FlipY != Old.FlipY || New.Instance != Old.Instance) { Shader.SetExtraData(New.FlipX, New.FlipY, New.Instance); } //Note: Uncomment SetFrontFace and SetCullFace when flipping issues are solved //if (New.FrontFace != O.FrontFace) //{ // GL.FrontFace(OGLEnumConverter.GetFrontFace(New.FrontFace)); //} //if (New.CullFaceEnabled != O.CullFaceEnabled) //{ // Enable(EnableCap.CullFace, New.CullFaceEnabled); //} //if (New.CullFaceEnabled) //{ // if (New.CullFace != O.CullFace) // { // GL.CullFace(OGLEnumConverter.GetCullFace(New.CullFace)); // } //} if (New.DepthTestEnabled != Old.DepthTestEnabled) { Enable(EnableCap.DepthTest, New.DepthTestEnabled); } if (New.DepthTestEnabled) { if (New.DepthFunc != Old.DepthFunc) { GL.DepthFunc(OGLEnumConverter.GetDepthFunc(New.DepthFunc)); } } if (New.StencilTestEnabled != Old.StencilTestEnabled) { Enable(EnableCap.StencilTest, New.StencilTestEnabled); } if (New.StencilTestEnabled) { if (New.StencilBackFuncFunc != Old.StencilBackFuncFunc || New.StencilBackFuncRef != Old.StencilBackFuncRef || New.StencilBackFuncMask != Old.StencilBackFuncMask) { GL.StencilFuncSeparate( StencilFace.Back, OGLEnumConverter.GetStencilFunc(New.StencilBackFuncFunc), New.StencilBackFuncRef, New.StencilBackFuncMask); } if (New.StencilBackOpFail != Old.StencilBackOpFail || New.StencilBackOpZFail != Old.StencilBackOpZFail || New.StencilBackOpZPass != Old.StencilBackOpZPass) { GL.StencilOpSeparate( StencilFace.Back, OGLEnumConverter.GetStencilOp(New.StencilBackOpFail), OGLEnumConverter.GetStencilOp(New.StencilBackOpZFail), OGLEnumConverter.GetStencilOp(New.StencilBackOpZPass)); } if (New.StencilBackMask != Old.StencilBackMask) { GL.StencilMaskSeparate(StencilFace.Back, New.StencilBackMask); } if (New.StencilFrontFuncFunc != Old.StencilFrontFuncFunc || New.StencilFrontFuncRef != Old.StencilFrontFuncRef || New.StencilFrontFuncMask != Old.StencilFrontFuncMask) { GL.StencilFuncSeparate( StencilFace.Front, OGLEnumConverter.GetStencilFunc(New.StencilFrontFuncFunc), New.StencilFrontFuncRef, New.StencilFrontFuncMask); } if (New.StencilFrontOpFail != Old.StencilFrontOpFail || New.StencilFrontOpZFail != Old.StencilFrontOpZFail || New.StencilFrontOpZPass != Old.StencilFrontOpZPass) { GL.StencilOpSeparate( StencilFace.Front, OGLEnumConverter.GetStencilOp(New.StencilFrontOpFail), OGLEnumConverter.GetStencilOp(New.StencilFrontOpZFail), OGLEnumConverter.GetStencilOp(New.StencilFrontOpZPass)); } if (New.StencilFrontMask != Old.StencilFrontMask) { GL.StencilMaskSeparate(StencilFace.Front, New.StencilFrontMask); } } if (New.BlendEnabled != Old.BlendEnabled) { Enable(EnableCap.Blend, New.BlendEnabled); } if (New.BlendEnabled) { if (New.BlendSeparateAlpha) { if (New.BlendEquationRgb != Old.BlendEquationRgb || New.BlendEquationAlpha != Old.BlendEquationAlpha) { GL.BlendEquationSeparate( OGLEnumConverter.GetBlendEquation(New.BlendEquationRgb), OGLEnumConverter.GetBlendEquation(New.BlendEquationAlpha)); } if (New.BlendFuncSrcRgb != Old.BlendFuncSrcRgb || New.BlendFuncDstRgb != Old.BlendFuncDstRgb || New.BlendFuncSrcAlpha != Old.BlendFuncSrcAlpha || New.BlendFuncDstAlpha != Old.BlendFuncDstAlpha) { GL.BlendFuncSeparate( (BlendingFactorSrc)OGLEnumConverter.GetBlendFactor(New.BlendFuncSrcRgb), (BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.BlendFuncDstRgb), (BlendingFactorSrc)OGLEnumConverter.GetBlendFactor(New.BlendFuncSrcAlpha), (BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.BlendFuncDstAlpha)); } } else { if (New.BlendEquationRgb != Old.BlendEquationRgb) { GL.BlendEquation(OGLEnumConverter.GetBlendEquation(New.BlendEquationRgb)); } if (New.BlendFuncSrcRgb != Old.BlendFuncSrcRgb || New.BlendFuncDstRgb != Old.BlendFuncDstRgb) { GL.BlendFunc( OGLEnumConverter.GetBlendFactor(New.BlendFuncSrcRgb), OGLEnumConverter.GetBlendFactor(New.BlendFuncDstRgb)); } } } if (New.PrimitiveRestartEnabled != Old.PrimitiveRestartEnabled) { Enable(EnableCap.PrimitiveRestart, New.PrimitiveRestartEnabled); } if (New.PrimitiveRestartEnabled) { if (New.PrimitiveRestartIndex != Old.PrimitiveRestartIndex) { GL.PrimitiveRestartIndex(New.PrimitiveRestartIndex); } } Old = New; }