protected override bool BeginRenderEffectOverride(Texture texture, RenderContext renderContext) { if (_refresh) { _imageContext = new ImageContext(); _refresh = false; } RectangleF rect = renderContext.OccupiedTransformedBounds; SizeF frameSize = new SizeF(rect.Width, rect.Height); _imageContext.FrameSize = frameSize; _imageContext.ExtraParameters = GetShaderParameters(); _imageContext.ShaderEffect = SkinResources.EFFECTS_SUB_DIRECTORY + '\\' + _partialShaderEffect; Vector4 lastFrameData = new Vector4(rect.Width, rect.Height, 0.0f, 0.0f); _imageContext.StartRender(renderContext, frameSize, texture, CROP_FULLSIZE, Color.Transparent, lastFrameData); return true; }
protected void CycleTextures(RightAngledRotation rotation) { // Current -> Last _lastTexture = _currentTexture; _lastImageContext = _imageContext; // Next -> Current _currentTexture = _nextTexture; _imageContext = new ImageContext { FrameSize = _frameSize, ShaderEffect = Effect, Rotation = rotation }; // Clear next _nextTexture = null; if (_lastTexture != _currentTexture) { StartTransition(); FireChanged(); } }
void Init() { _streamProperty = new SProperty(typeof(int), 0); _geometryProperty = new SProperty(typeof(string), null); _borderColorProperty = new SProperty(typeof(Color), Color.Black); _imageContext = new ImageContext { OnRefresh = OnImagecontextRefresh, ExtraParameters = new System.Collections.Generic.Dictionary<string, object>() }; }
protected void CycleTextures(Texture nextTexture, RectangleF textureClip, RightAngledRotation nextRotation) { TryDispose(ref _lastTexture); // Current -> Last _lastTexture = _currentTexture; _lastRawSourceSize = _currentClippedSize; _lastTextureClip = _currentTextureClip; _lastImageContext = _imageContext; // Next -> Current SizeF textureSize; _currentTexture = CreateTextureCopy(nextTexture, out textureSize); _currentTextureSize = textureSize; UpdateTextureClip(textureClip); _imageContext = new ImageContext { FrameSize = _frameSize, ShaderEffect = Effect, Rotation = nextRotation }; StartTransition(); FireChanged(); }
/// <summary> /// Starts a rendering operation where two images are mixed together using a transition effect. /// </summary> /// <param name="renderContext">The current rendering context.</param> /// <param name="mixValue">A value between 0.0 and 1.0 that governs how much each image contributes to the final rendering.</param> /// <param name="startContext">The <see cref="ImageContext"/> data for the starting position of the transition /// (this context is the end point).</param> /// <param name="targetEndImageSize">The size, the final end image should take within the frame. This size is given in the same /// orientation as the <paramref name="endTexture"/>, i.e. it is not rotated.</param> /// <param name="endTexture">A texture object containing the end image.</param> /// <param name="endTextureClip">The section of the end texture that should be rendered. Values are between 0 and 1.</param> /// <param name="borderColor">The color to use outside the image's boundaries.</param> /// <param name="startFrameData">Additional data to be used by the starting image shaders.</param> /// <param name="endFrameData">Additional data to be used by the ending image shaders.</param> /// <returns><c>true</c> if the rendering operation was started.</returns> public bool StartRenderTransition(RenderContext renderContext, float mixValue, ImageContext startContext, SizeF targetEndImageSize, Texture endTexture, RectangleF endTextureClip, Color borderColor, Vector4 startFrameData, Vector4 endFrameData) { RefreshParameters(targetEndImageSize, endTexture, endTextureClip); if (_effectTransition == null) _effectTransition = ContentManager.Instance.GetEffect(GetTransitionEffectName()); if (_lastTexture == null || _effectTransition == null) return false; // Apply effect parameters _effectTransition.Parameters[PARAM_OPACITY] = (float) renderContext.Opacity; _effectTransition.Parameters[PARAM_RELATIVE_TRANSFORM] = _inverseRelativeTransformCache; _effectTransition.Parameters[PARAM_BRUSH_TRANSFORM] = _imageTransform; _effectTransition.Parameters[PARAM_FRAME_DATA] = endFrameData; _effectTransition.Parameters[PARAM_MIX_AB] = mixValue; startContext.ApplyTransitionParametersAsStartingSource(_effectTransition, startFrameData); // Disable antialiasing for image rendering. GraphicsDevice.Device.SetRenderState(RenderState.MultisampleAntialias, false); // Set border colour for area outside of texture boundaries GraphicsDevice.Device.SetSamplerState(0, SamplerState.BorderColor, borderColor.ToBgra()); GraphicsDevice.Device.SetSamplerState(1, SamplerState.BorderColor, borderColor.ToBgra()); // Render _effectTransition.StartRender(_lastTexture, renderContext.Transform); return true; }
/// <summary> /// Starts a rendering operation where two images are mixed together using a transition effect. /// </summary> /// <param name="renderContext">The current rendering context.</param> /// <param name="mixValue">A value between 0.0 and 1.0 that governs how much each image contributes to the final rendering.</param> /// <param name="startContext">The <see cref="ImageContext"/> data for the starting position of the transition /// (this context is the end point).</param> /// <param name="targetEndImageSize">The size, the final end image should take within the frame. This size is given in the same /// orientation as the <paramref name="endTexture"/>, i.e. it is not rotated.</param> /// <param name="endTexture">A texture object containing the end image.</param> /// <param name="endTextureClip">The section of the end texture that should be rendered. Values are between 0 and 1.</param> /// <param name="borderColor">The color to use outside the image's boundaries.</param> /// <param name="startFrameData">Additional data to be used by the starting image shaders.</param> /// <param name="endFrameData">Additional data to be used by the ending image shaders.</param> /// <returns><c>true</c> if the rendering operation was started.</returns> public bool StartRenderTransition(RenderContext renderContext, float mixValue, ImageContext startContext, SizeF targetEndImageSize, Texture endTexture, RectangleF endTextureClip, Color borderColor, Vector4 startFrameData, Vector4 endFrameData) { RefreshParameters(targetEndImageSize, endTexture, endTextureClip); if (_effectTransition == null) { _effectTransition = ContentManager.Instance.GetEffect(GetTransitionEffectName()); } if (_lastTexture == null || _effectTransition == null) { return(false); } // Apply effect parameters _effectTransition.Parameters[PARAM_OPACITY] = (float)renderContext.Opacity; _effectTransition.Parameters[PARAM_RELATIVE_TRANSFORM] = _inverseRelativeTransformCache; _effectTransition.Parameters[PARAM_BRUSH_TRANSFORM] = _imageTransform; _effectTransition.Parameters[PARAM_FRAME_DATA] = endFrameData; _effectTransition.Parameters[PARAM_MIX_AB] = mixValue; startContext.ApplyTransitionParametersAsStartingSource(_effectTransition, startFrameData); // Disable antialiasing for image rendering. GraphicsDevice.Device.SetRenderState(RenderState.MultisampleAntialias, false); // Set border colour for area outside of texture boundaries GraphicsDevice.Device.SetSamplerState(0, SamplerState.BorderColor, borderColor.ToBgra()); GraphicsDevice.Device.SetSamplerState(1, SamplerState.BorderColor, borderColor.ToBgra()); // Render _effectTransition.StartRender(_lastTexture, renderContext.Transform); return(true); }