public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters)
        {
            gameWindow = (iPhoneOSGameView)Description.DeviceWindowHandle.NativeHandle;
            device.InitDefaultRenderTarget(presentationParameters);

            backBuffer = Texture.New2D(device, Description.BackBufferWidth, Description.BackBufferHeight, presentationParameters.BackBufferFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource);
        }
Esempio n. 2
0
        /// <summary>
        /// Draws the specified texture.
        /// </summary>
        /// <param name="texture">The texture.</param>
        /// <param name="position">The position.</param>
        /// <param name="renderSize">Size of the render.</param>
        /// <param name="color">The color.</param>
        /// <param name="source">The source.</param>
        /// <param name="centerOrigin">if set to <c>true</c> [center origin].</param>
        public override void Draw(TextureBase texture, PointF position, Size renderSize, ColorW color, Rect source, bool centerOrigin)
        {
            testRectangle.X      = (int)position.X;
            testRectangle.Y      = (int)position.Y;
            testRectangle.Width  = (int)renderSize.Width;
            testRectangle.Height = (int)renderSize.Height;
            if (isClipped && !currentScissorRectangle.Intersects(testRectangle))
            {
                return;
            }

            sourceRect.X      = (int)source.X;
            sourceRect.Y      = (int)source.Y;
            sourceRect.Width  = (int)source.Width;
            sourceRect.Height = (int)source.Height;
            vecColor.A        = color.A;
            vecColor.R        = color.R;
            vecColor.G        = color.G;
            vecColor.B        = color.B;
            if (centerOrigin)
            {
                origin.X = testRectangle.Width / 2f;
                origin.Y = testRectangle.Height / 2f;
            }

            Texture2D native = texture.GetNativeTexture() as Texture2D;

            spriteBatch.Draw(native, testRectangle, sourceRect, vecColor, 0, origin);
        }
Esempio n. 3
0
        /// <summary>
        /// Unbinds all depth-stencil buffer and render targets from the output-merger stage.
        /// </summary>
        public void ResetTargets()
        {
            ResetTargetsImpl();

            depthStencilBuffer = null;
            for (int i = 0; i < renderTargets.Length; i++)
                renderTargets[i] = null;
        }
        /// <summary>
        /// Frees previously acquired SRV texture. Should be called when the view is no longer needed
        /// </summary>
        /// <param name="depthAsSR">The previously acquired SRV texture</param>
        public void ReleaseDepthStenctilAsShaderResource(Texture depthAsSR)
        {
            // If no resources were allocated in the first place there is nothing to release
            if (depthAsSR == null || !renderContext.GraphicsDevice.Features.HasDepthAsSRV || renderContext.GraphicsDevice.Features.HasDepthAsReadOnlyRT)
                return;

            renderContext.RenderContext.Allocator.ReleaseReference(depthAsSR);
        }
 public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters)
 {
     device.Begin();
     device.InitDefaultRenderTarget(presentationParameters);
     device.End();
     backBuffer = device.DefaultRenderTarget;
     DepthStencilBuffer = device.windowProvidedDepthTexture;
 }
        /// <summary>
        /// Gets a texture view which can be used to copy the depth buffer
        /// </summary>
        /// <param name="texture">The depthStencil texture originally used for render target</param>
        /// <returns>A texture view which can be used to copy the depth buffer</returns>
        private Texture GetDepthStenctilAsShaderResource_Copy(Texture texture)
        {
            var textureDescription = texture.Description;
            textureDescription.Flags = TextureFlags.ShaderResource;
            textureDescription.Format = PixelFormat.R24_UNorm_X8_Typeless;

            return renderContext.RenderContext.Allocator.GetTemporaryTexture2D(textureDescription);
        }
Esempio n. 7
0
        /// <summary>
        /// Draws the geometry texture.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="position">The position.</param>
        /// <param name="texture">The texture.</param>
        /// <param name="opacity">The opacity.</param>
        /// <param name="depth">The depth.</param>
        public override void DrawGeometryTexture(GeometryBuffer buffer, PointF position, TextureBase texture, float opacity, float depth)
        {
            XenkoGeometryBuffer paradoxBuffer = buffer as XenkoGeometryBuffer;
            Texture2D           nativeTexture = texture.GetNativeTexture() as Texture2D;

            paradoxBuffer.EffectInstance.Parameters.Set(SpriteEffectKeys.Color, Color.White * opacity);
            paradoxBuffer.EffectInstance.Parameters.Set(TexturingKeys.Texture0, nativeTexture);
            DrawGeometry(buffer, position, depth);
        }
        /// <summary>
        /// Returns a texture view which should be used as DepthStencil Shader Resource View. Can be <c>null</c> if not supported
        /// </summary>
        /// <param name="texture">The depthStencil texture originally used for render target</param>
        /// <returns>The texture view which should be used as DepthStencil SRV. Can be <c>null</c> if not supported</returns>
        public Texture GetDepthStenctilAsShaderResource(Texture texture)
        {
            if (!renderContext.GraphicsDevice.Features.HasDepthAsSRV)
                return null;

            if (renderContext.GraphicsDevice.Features.HasDepthAsReadOnlyRT)
                return texture;

            return GetDepthStenctilAsShaderResource_Copy(texture);
        }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComputeTextureColor" /> class.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="texcoordIndex">Index of the texcoord.</param>
 /// <param name="scale">The scale.</param>
 /// <param name="offset">The offset.</param>
 protected ComputeTextureBase(Texture texture, TextureCoordinate texcoordIndex, Vector2 scale, Vector2 offset)
 {
     Enabled = true;
     Texture = texture;
     TexcoordIndex = texcoordIndex;
     Sampler = new ComputeColorParameterSampler();
     Scale = scale;
     Offset = offset;
     Key = null;
 }
Esempio n. 10
0
        public ShadowMapAtlasTexture(Texture texture, int textureId)
        {
            if (texture == null) throw new ArgumentNullException("texture");
            Texture = texture;
            Clear(Texture.Width, Texture.Height);
            Width = texture.Width;
            Height = texture.Height;

            RenderFrame = RenderFrame.FromTexture((Texture)null, texture);
            Id = textureId;
        }
        /// <summary>
        /// Returns a texture view which should be used as DepthStencil render target while SRV is also used
        /// </summary>
        /// <param name="texture">The depthStencil texture originally used for render target</param>
        /// <param name="readOnlyCached">The cached view for the texture resource</param>
        /// <returns>The texture view which should be used as DepthStencil render target while SRV is also used</returns>
        public Texture GetDepthStencilAsRenderTarget(Texture texture, Texture readOnlyCached)
        {
            if (!renderContext.GraphicsDevice.Features.HasDepthAsSRV || !renderContext.GraphicsDevice.Features.HasDepthAsReadOnlyRT)
                return texture;

            // Check if changed
            if (readOnlyCached != null && readOnlyCached.ParentTexture == texture)
                return readOnlyCached;

            return texture.ToDepthStencilReadOnlyTexture();
        }
Esempio n. 12
0
        /// <summary>
        /// Sets an input texture
        /// </summary>
        /// <param name="slot">The slot.</param>
        /// <param name="texture">The texture.</param>
        public void SetInput(int slot, Texture texture)
        {
            if (slot < 0 || slot >= inputTextures.Length)
                throw new ArgumentOutOfRangeException("slot", "slot must be in the range [0, 128[");

            inputTextures[slot] = texture;
            if (slot > maxInputTextureIndex)
            {
                maxInputTextureIndex = slot;
            }
        }
        public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
            : base(device, presentationParameters)
        {
            PresentInterval = presentationParameters.PresentationInterval;

            backbuffer = new Texture(device);

            CreateSurface();

            // Initialize the swap chain
            CreateSwapChain();
        }
        public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
            : base(device, presentationParameters)
        {
            PresentInterval = presentationParameters.PresentationInterval;

            // Initialize the swap chain
            swapChain = CreateSwapChain();

            backBuffer = new Texture(device).InitializeFrom(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture2D>(0), Description.BackBufferFormat.IsSRgb());

            // Reload should get backbuffer from swapchain as well
            //backBufferTexture.Reload = graphicsResource => ((Texture)graphicsResource).Recreate(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture>(0));
        }
Esempio n. 15
0
 /// <summary>
 /// Creates a <see cref="Sprite"/> having the provided texture and name.
 /// The region size is initialized with the whole size of the texture.
 /// </summary>
 /// <param name="fragmentName">The name of the sprite</param>
 /// <param name="texture">The texture to use as texture</param>
 public Sprite(string fragmentName, Texture texture)
 {
     Name = fragmentName;
     PixelsPerUnit = new Vector2(DefaultPixelsPerUnit);
     IsTransparent = true;
     
     Texture = texture;
     if (texture != null)
     {
         Region = new Rectangle(0, 0, texture.ViewWidth, texture.ViewHeight);
         Center = new Vector2(Region.Width/2, Region.Height/2);
     }
 }
        private SpriteFromTexture(Sprite source)
            : this()
        {
            sprite = source;
            isSpriteDirty = false;

            center = sprite.Center;
            centerFromMiddle = false;
            isTransparent = sprite.IsTransparent;
            // FIXME: should we use the Max, Min, average of X and/or Y?
            pixelsPerUnit = sprite.PixelsPerUnit.X;
            texture = sprite.Texture;
        }
Esempio n. 17
0
        protected override void InitializeCore()
        {
            base.InitializeCore();

            LuminanceLogEffect = ToLoadAndUnload(new LuminanceLogEffect());

            // Create 1x1 texture
            luminance1x1 = Texture.New2D(GraphicsDevice, 1, 1, 1, luminanceFormat, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this);

            // Use a multiscaler
            multiScaler = ToLoadAndUnload(new ImageMultiScaler());

            // Readback is always going to be done on the 1x1 texture
            readback = ToLoadAndUnload(readback);

            // Blur used before upscaling 
            blur = ToLoadAndUnload(new GaussianBlur());
            blur.Radius = 4;
        }
        private void CreateBackground(Texture bgTexture, RectangleF texReg)
        {
            texture = bgTexture;
            textureRegion = texReg;

            // Set offset to rectangle
            firstQuadRegion.X = textureRegion.X;
            firstQuadRegion.Y = textureRegion.Y;

            firstQuadRegion.Width = (textureRegion.Width > screenResolution.X) ? screenResolution.X : textureRegion.Width;
            firstQuadRegion.Height = (textureRegion.Height > screenResolution.Y) ? screenResolution.Y : textureRegion.Height;

            // Centering the content
            firstQuadOrigin.X = 0.5f * firstQuadRegion.Width;
            firstQuadOrigin.Y = 0.5f * firstQuadRegion.Height;

            // Copy data from first quad to second one
            secondQuadRegion = firstQuadRegion;
            secondQuadOrigin = firstQuadOrigin;
        }
Esempio n. 19
0
        /// <summary>
        /// Creates the texture.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="mipmap">if set to <c>true</c> [mipmap].</param>
        /// <param name="dynamic">if set to <c>true</c> [dynamic].</param>
        /// <returns></returns>
        public override TextureBase CreateTexture(int width, int height, bool mipmap, bool dynamic)
        {
            if (width == 0 || height == 0)
            {
                return(null);
            }

            Texture2D native = null;

            if (dynamic)
            {
                native = Texture2D.New2D(GraphicsDevice, width, height, PixelFormat.R8G8B8A8_UNorm, usage: GraphicsResourceUsage.Dynamic);
            }
            else
            {
                native = Texture2D.New2D(GraphicsDevice, width, height, PixelFormat.R8G8B8A8_UNorm);
            }

            XenkoTexture texture = new XenkoTexture(native);

            return(texture);
        }
        // Complete the graphic pipeline, initialize texture data
        public override void Start()
        {
            // create the sprite batch used in our custom rendering function
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // insert the custom renderer in between the 2 camera renderer.
            var scene = SceneSystem.SceneInstance.Scene;
            var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor);
            compositor.Master.Renderers.Insert(2, new SceneDelegateRenderer(RenderTexture));
            
            // Create and initialize the dynamic texture
            renderTexture = Texture.New2D(GraphicsDevice, RenderTextureSize, RenderTextureSize, 1, PixelFormat.R8G8B8A8_UNorm_SRgb, usage: GraphicsResourceUsage.Dynamic);

            // Setup initial data in "SymmetricDefaultShape" to the texture
            for (var i = 0; i < SymmetricDefaultShape.Length; i += 2)
            {
                TogglePixel(SymmetricDefaultShape[i], SymmetricDefaultShape[i + 1]);
                if (SymmetricDefaultShape[i] != (RenderTextureSize - 1) - SymmetricDefaultShape[i])
                    TogglePixel((RenderTextureSize - 1) - SymmetricDefaultShape[i], SymmetricDefaultShape[i + 1]);
            }

            renderTexture.SetData(Game.GraphicsContext.CommandList, textureData);
        }
 /// <summary>
 /// Draws a fullscreen texture using the specified sampler. See <see cref="Draw+a+texture"/> to learn how to use it.
 /// </summary>
 /// <param name="texture">The texture. Expecting an instance of <see cref="Texture"/>.</param>
 /// <param name="sampler">The sampler.</param>
 /// <param name="applyEffectStates">The flag to apply effect states.</param>
 public static void DrawTexture(this GraphicsContext graphicsContext, Texture texture, SamplerState sampler, BlendStateDescription? blendState = null)
 {
     graphicsContext.DrawTexture(texture, sampler, Color4.White, blendState);
 }
        /// <summary>
        /// Calls <see cref="Texture.OnDestroyed"/> for all children of the specified texture
        /// </summary>
        /// <param name="parentTexture">Specified parent texture</param>
        /// <returns>A list of the children textures which were destroyed</returns>
        private FastList<Texture> DestroyChildrenTextures(Texture parentTexture)
        {
            var fastList = new FastList<Texture>();
            foreach (var resource in GraphicsDevice.Resources)
            {
                var texture = resource as Texture;
                if (texture != null && texture.ParentTexture == parentTexture)
                {
                    texture.OnDestroyed();
                    fastList.Add(texture);
                }
            }

            return fastList;
        }
Esempio n. 23
0
 /// <summary>
 /// Adds a sprite to a batch of sprites for rendering using the specified texture, destination rectangle, and color.
 /// </summary>
 /// <param name="texture">A texture.</param>
 /// <param name="destinationRectangle">A rectangle that specifies (in screen coordinates) the destination for drawing the sprite.</param>
 /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
 /// <remarks>
 /// Before making any calls to Draw, you must call Begin. Once all calls to Draw are complete, call End.
 /// </remarks>
 public void Draw(Texture texture, RectangleF destinationRectangle, Color4 color, Color4 colorAdd = default(Color4))
 {
     DrawSprite(texture, ref destinationRectangle, false, ref nullRectangle, color, colorAdd, 0f, ref vector2Zero, SpriteEffects.None, ImageOrientation.AsIs, 0f);
 }
Esempio n. 24
0
 /// <summary>
 /// Adds a sprite to a batch of sprites for rendering using the specified texture, position and color.
 /// </summary>
 /// <param name="texture">A texture.</param>
 /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
 public void Draw(Texture texture, Vector2 position)
 {
     Draw(texture, position, Color.White);
 }
Esempio n. 25
0
 /// <summary>
 /// Adds a sprite to a batch of sprites for rendering using the specified texture, destination rectangle, source rectangle, color, rotation, origin, effects and layer.
 /// </summary>
 /// <param name="texture">A texture.</param>
 /// <param name="orientation">The source image orientation</param>
 /// <param name="destinationRectangle">A rectangle that specifies (in screen coordinates) the destination for drawing the sprite. If this rectangle is not the same size as the source rectangle, the sprite will be scaled to fit.</param>
 /// <param name="sourceRectangle">A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture. </param>
 /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
 /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
 /// <param name="origin">The sprite origin in the texture in pixels (dependent of image orientation). Default value is (0,0) which represents the upper-left corner.</param>
 /// <param name="effects">Effects to apply.</param>
 /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
 public void Draw(Texture texture, RectangleF destinationRectangle, RectangleF?sourceRectangle, Color4 color, float rotation, Vector2 origin,
                  SpriteEffects effects = SpriteEffects.None, ImageOrientation orientation = ImageOrientation.AsIs, float layerDepth = 0f, Color4 colorAdd = default(Color4), SwizzleMode swizzle = SwizzleMode.None)
 {
     DrawSprite(texture, ref destinationRectangle, false, ref sourceRectangle, color, colorAdd, rotation, ref origin, effects, orientation, layerDepth, swizzle);
 }
Esempio n. 26
0
        protected override void InitializeCore()
        {
            base.InitializeCore();

            coclinearDepthMapEffect = ToLoadAndUnload(new ImageEffectShader("CoCLinearDepthShader"));
            combineLevelsEffect = ToLoadAndUnload(new ImageEffectShader("CombineLevelsFromCoCEffect"));
            combineLevelsFrontEffect = ToLoadAndUnload(new ImageEffectShader("CombineFrontCoCEffect"));
            combineLevelsFrontEffect.BlendState = BlendStates.AlphaBlend;
            textureScaler = ToLoadAndUnload(new ImageScaler());
            cocMapBlur = ToLoadAndUnload(new CoCMapBlur());
            thresholdAlphaCoC = ToLoadAndUnload(new ImageEffectShader("ThresholdAlphaCoC"));
            thresholdAlphaCoCFront = ToLoadAndUnload(new ImageEffectShader("ThresholdAlphaCoCFront"));
            pointDepthShader = ToLoadAndUnload(new ImageEffectShader("PointDepth"));
            depthReadBack = ToLoadAndUnload(new ImageReadback<Half>());
            depthCenter1x1 = Texture.New2D(GraphicsDevice, 1, 1, 1, PixelFormat.R16_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this);
        }
Esempio n. 27
0
 public LuminanceResult(float averageLuminance, Texture localTexture)
     : this()
 {
     AverageLuminance = averageLuminance;
     LocalTexture = localTexture;
 }
 public ParameterKey<Texture> GetTextureKey(Texture texture, ParameterKey<Texture> key, Color? defaultTextureValue = null)
 {
     var textureKey = (ParameterKey<Texture>)GetParameterKey(key);
     if (texture != null)
     {
         Parameters.Set(textureKey, texture);
     }
     else if (defaultTextureValue != null && Assets != null)
     {
         texture = GenerateTextureFromColor(defaultTextureValue.Value);
         Parameters.Set(textureKey, texture);
     }
     return textureKey;
 }
Esempio n. 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComputeTextureColor"/> class.
 /// </summary>
 /// <param name="texture">The texture.</param>
 public ComputeTextureColor(Texture texture)
     : this(texture, TextureCoordinate.Texcoord0, Vector2.One, Vector2.Zero)
 {
 }
Esempio n. 30
0
 /// <summary>
 /// Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.
 /// </summary>
 /// <param name="texture">A texture.</param>
 /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
 /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
 /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
 /// <param name="origin">The sprite origin in the texture in pixels (dependent of image orientation). Default value is (0,0) which represents the upper-left corner.</param>
 /// <param name="scale">Scale factor.</param>
 /// <param name="effects">Effects to apply.</param>
 /// <param name="orientation">The source image orientation</param>
 /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
 public void Draw(Texture texture, Vector2 position, Color4 color, float rotation, Vector2 origin, Vector2 scale,
                  SpriteEffects effects = SpriteEffects.None, ImageOrientation orientation = ImageOrientation.AsIs, float layerDepth = 0)
 {
     Draw(texture, position, null, color, rotation, origin, scale, effects, orientation, layerDepth);
 }
Esempio n. 31
0
        /// <summary>
        /// Draw a 3D sprite (or add it to the draw list depending on the sortMode).
        /// </summary>
        /// <param name="texture">The texture to use during the draw</param>
        /// <param name="worldMatrix">The world matrix of the element</param>
        /// <param name="sourceRectangle">The rectangle indicating the source region of the texture to use</param>
        /// <param name="elementSize">The size of the sprite in the object space</param>
        /// <param name="color">The color to apply to the texture image.</param>
        /// <param name="imageOrientation">The rotation to apply on the image uv</param>
        /// <param name="swizzle">Swizzle mode indicating the swizzle use when sampling the texture in the shader</param>
        /// <param name="depth">The depth of the element. If null, it is calculated using world and view-projection matrix.</param>
        public void Draw(Texture texture, ref Matrix worldMatrix, ref RectangleF sourceRectangle, ref Vector2 elementSize, ref Color4 color,
                         ImageOrientation imageOrientation = ImageOrientation.AsIs, SwizzleMode swizzle = SwizzleMode.None, float?depth = null)
        {
            // Check that texture is not null
            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }

            // Skip items with null size
            if (elementSize.Length() < MathUtil.ZeroTolerance)
            {
                return;
            }

            // Calculate the information needed to draw.
            var drawInfo = new Sprite3DDrawInfo
            {
                Source =
                {
                    X      = sourceRectangle.X / texture.ViewWidth,
                    Y      = sourceRectangle.Y / texture.ViewHeight,
                    Width  = sourceRectangle.Width / texture.ViewWidth,
                    Height = sourceRectangle.Height / texture.ViewHeight
                },
                Color   = color,
                Swizzle = swizzle,
            };

            var matrix = worldMatrix;

            matrix.M11 *= elementSize.X;
            matrix.M12 *= elementSize.X;
            matrix.M13 *= elementSize.X;
            matrix.M21 *= elementSize.Y;
            matrix.M22 *= elementSize.Y;
            matrix.M23 *= elementSize.Y;

            Vector4.Transform(ref vector4UnitX, ref matrix, out drawInfo.UnitXWorld);
            Vector4.Transform(ref vector4UnitY, ref matrix, out drawInfo.UnitYWorld);

            // rotate origin and unit axis if need.
            var leftTopCorner = new Vector4(-0.5f, 0.5f, 0, 1);

            if (imageOrientation == ImageOrientation.Rotated90)
            {
                var unitX = drawInfo.UnitXWorld;
                drawInfo.UnitXWorld = -drawInfo.UnitYWorld;
                drawInfo.UnitYWorld = unitX;
                leftTopCorner       = new Vector4(-0.5f, -0.5f, 0, 1);
            }
            Vector4.Transform(ref leftTopCorner, ref matrix, out drawInfo.LeftTopCornerWorld);

            float depthSprite;

            if (depth.HasValue)
            {
                depthSprite = depth.Value;
            }
            else
            {
                Vector4 projectedPosition;
                var     worldPosition = new Vector4(worldMatrix.TranslationVector, 1.0f);
                Vector4.Transform(ref worldPosition, ref transformationMatrix, out projectedPosition);
                depthSprite = projectedPosition.Z / projectedPosition.W;
            }

            var elementInfo = new ElementInfo(StaticQuadBufferInfo.VertexByElement, StaticQuadBufferInfo.IndicesByElement, ref drawInfo, depthSprite);

            Draw(texture, ref elementInfo);
        }
Esempio n. 32
0
        /// <summary>
        /// Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, and color.
        /// </summary>
        /// <param name="texture">A texture.</param>
        /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
        /// <param name="sourceRectangle">A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture. </param>
        /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
        public void Draw(Texture texture, Vector2 position, RectangleF?sourceRectangle, Color4 color, Color4 colorAdd = default(Color4))
        {
            var destination = new RectangleF(position.X, position.Y, 1f, 1f);

            DrawSprite(texture, ref destination, true, ref sourceRectangle, color, colorAdd, 0f, ref vector2Zero, SpriteEffects.None, ImageOrientation.AsIs, 0f);
        }
Esempio n. 33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MonoGameTexture"/> class.
 /// </summary>
 /// <param name="nativeTexture">The native texture.</param>
 public XenkoTexture(object nativeTexture)
     : base(nativeTexture)
 {
     texture = nativeTexture as Texture2D;
 }
Esempio n. 34
0
        internal unsafe void DrawSprite(Texture texture, ref RectangleF destination, bool scaleDestination, ref RectangleF?sourceRectangle, Color4 color, Color4 colorAdd,
                                        float rotation, ref Vector2 origin, SpriteEffects effects, ImageOrientation orientation, float depth, SwizzleMode swizzle = SwizzleMode.None, bool realSize = false)
        {
            // Check that texture is not null
            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }

            // Put values in next ElementInfo
            var elementInfo = new ElementInfo();
            var spriteInfo  = &elementInfo.DrawInfo;

            float width;
            float height;

            // If the source rectangle has a value, then use it.
            if (sourceRectangle.HasValue)
            {
                var rectangle = sourceRectangle.Value;
                spriteInfo->Source.X = rectangle.X;
                spriteInfo->Source.Y = rectangle.Y;
                width  = rectangle.Width;
                height = rectangle.Height;
            }
            else
            {
                // Else, use directly the size of the texture
                spriteInfo->Source.X = 0.0f;
                spriteInfo->Source.Y = 0.0f;
                width  = texture.ViewWidth;
                height = texture.ViewHeight;
            }

            // Sets the width and height
            spriteInfo->Source.Width  = width;
            spriteInfo->Source.Height = height;

            // Scale the destination box
            if (scaleDestination)
            {
                if (orientation == ImageOrientation.Rotated90)
                {
                    destination.Width  *= height;
                    destination.Height *= width;
                }
                else
                {
                    destination.Width  *= width;
                    destination.Height *= height;
                }
            }

            // Sets the destination
            spriteInfo->Destination = destination;

            // Copy all other values.
            spriteInfo->Origin.X      = origin.X;
            spriteInfo->Origin.Y      = origin.Y;
            spriteInfo->Rotation      = rotation;
            spriteInfo->Depth         = depth;
            spriteInfo->SpriteEffects = effects;
            spriteInfo->ColorScale    = color;
            spriteInfo->ColorAdd      = colorAdd;
            spriteInfo->Swizzle       = swizzle;
            spriteInfo->TextureSize.X = texture.ViewWidth;
            spriteInfo->TextureSize.Y = texture.ViewHeight;
            spriteInfo->Orientation   = orientation;

            elementInfo.VertexCount = StaticQuadBufferInfo.VertexByElement;
            elementInfo.IndexCount  = StaticQuadBufferInfo.IndicesByElement;
            elementInfo.Depth       = depth;

            Draw(texture, ref elementInfo);
        }
Esempio n. 35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComputeTextureColor" /> class.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="texcoordIndex">Index of the texcoord.</param>
 /// <param name="scale">The scale.</param>
 /// <param name="offset">The offset.</param>
 public ComputeTextureColor(Texture texture, TextureCoordinate texcoordIndex, Vector2 scale, Vector2 offset)
     : base(texture, texcoordIndex, scale, offset)
 {
     FallbackValue = new ComputeColor(Color4.White);
 }
 /// <summary>
 /// Draws a fullscreen texture using a <see cref="SamplerStateFactory.LinearClamp"/> sampler
 /// and the texture color multiplied by a custom color. See <see cref="Draw+a+texture"/> to learn how to use it.
 /// </summary>
 /// <param name="texture">The texture. Expecting an instance of <see cref="Texture"/>.</param>
 /// <param name="color">The color.</param>
 /// <param name="applyEffectStates">The flag to apply effect states.</param>
 public static void DrawTexture(this GraphicsContext graphicsContext, Texture texture, Color4 color, BlendStateDescription? blendState = null)
 {
     graphicsContext.DrawTexture(texture, null, color, blendState);
 }
Esempio n. 37
0
 /// <summary>
 /// Provides a color buffer and a depth buffer to apply the depth-of-field to.
 /// </summary>
 /// <param name="colorBuffer">A color buffer to process.</param>
 /// <param name="depthBuffer">The depth buffer corresponding to the color buffer provided.</param>
 public void SetColorDepthInput(Texture colorBuffer, Texture depthBuffer)
 {
     SetInput(0, colorBuffer);
     SetInput(1, depthBuffer);
 }
 /// <summary>
 /// Draws a fullscreen texture using the specified sampler
 /// and the texture color multiplied by a custom color. See <see cref="Draw+a+texture"/> to learn how to use it.
 /// </summary>
 /// <param name="texture">The texture. Expecting an instance of <see cref="Texture"/>.</param>
 /// <param name="sampler">The sampler.</param>
 /// <param name="color">The color.</param>
 /// <param name="applyEffectStates">The flag to apply effect states.</param>
 public static void DrawTexture(this GraphicsContext graphicsContext, Texture texture, SamplerState sampler, Color4 color, BlendStateDescription? blendState = null)
 {
     graphicsContext.CommandList.GraphicsDevice.PrimitiveQuad.Draw(graphicsContext, texture, sampler, color, blendState);
 }
            public void SetShadowMapShaderData(int index, ILightShadowMapShaderData shaderData)
            {
                var singleLightData = (LightDirectionalShadowMapShaderData)shaderData;
                var splits = singleLightData.CascadeSplits;
                var matrices = singleLightData.WorldToShadowCascadeUV;
                int splitIndex = index * cascadeCount;
                for (int i = 0; i < splits.Length; i++)
                {
                    cascadeSplits[splitIndex + i] = splits[i];
                    worldToShadowCascadeUV[splitIndex + i] = matrices[i];
                }

                depthBiases[index] = singleLightData.DepthBias;
                offsetScales[index] = singleLightData.OffsetScale;

                // TODO: should be setup just once at creation time
                if (index == 0)
                {
                    shadowMapTexture = singleLightData.Texture;
                    if (shadowMapTexture != null)
                    {
                        shadowMapTextureSize = new Vector2(shadowMapTexture.Width, shadowMapTexture.Height);
                        shadowMapTextureTexelSize = 1.0f / shadowMapTextureSize;
                    }
                }
            }
Esempio n. 40
0
        private void SaveTexture(Texture texture, string filename)
        {
            using (var image = texture.GetDataAsImage())
            {
                //Send to server and store to disk
                var imageData = new TestResultImage { CurrentVersion = "1.0", Frame = "0", Image = image, TestName = "" };
                var payload = new ScreenShotPayload { FileName = filename };
                var resultFileStream = new MemoryStream();
                var writer = new BinaryWriter(resultFileStream);
                imageData.Write(writer);

                Task.Run(() =>
                {
                    payload.Data = resultFileStream.ToArray();
                    payload.Size = payload.Data.Length;
                    socketMessageLayer.Send(payload).Wait();
                    resultFileStream.Dispose();
                });
            }
        }
Esempio n. 41
0
        /// <summary>
        /// Sets the render target output.
        /// </summary>
        /// <param name="view">The render target output view.</param>
        /// <exception cref="System.ArgumentNullException">view</exception>
        public void SetOutput(Texture view)
        {
            if (view == null) throw new ArgumentNullException("view");

            SetOutputInternal(view);
        }
Esempio n. 42
0
        public void CopyMultiSample(Texture sourceMsaaTexture, int sourceSubResource, Texture destTexture, int destSubResource, PixelFormat format = PixelFormat.None)
        {
            if (sourceMsaaTexture == null)
            {
                throw new ArgumentNullException("sourceMsaaTexture");
            }
            if (destTexture == null)
            {
                throw new ArgumentNullException("destTexture");
            }
            if (!sourceMsaaTexture.IsMultiSample)
            {
                throw new ArgumentOutOfRangeException("sourceMsaaTexture", "Source texture is not a MSAA texture");
            }

            NativeDeviceContext.ResolveSubresource(sourceMsaaTexture.NativeResource, sourceSubResource, destTexture.NativeResource, destSubResource, (SharpDX.DXGI.Format)(format == PixelFormat.None ? destTexture.Format : format));
        }