示例#1
0
        public void MoveCameraX(UltravioletContext context, int x)
        {
            Ultraviolet.Graphics.Viewport viewport = Ultraviolet.GetGraphics().GetViewport();

            viewport.X = viewport.X + x;
            context.GetGraphics().SetViewport(viewport);
        }
示例#2
0
        public void MoveCameraY(UltravioletContext context, int y)
        {
            Ultraviolet.Graphics.Viewport viewport = Ultraviolet.GetGraphics().GetViewport();

            viewport.Y = viewport.Y + y;
            context.GetGraphics().SetViewport(viewport);
        }
示例#3
0
        public void ChangePositionY(UltravioletContext context, int y)
        {
            Ultraviolet.Graphics.Viewport viewport = Ultraviolet.GetGraphics().GetViewport();

            viewport.Y = y;
            context.GetGraphics().SetViewport(viewport);
        }
示例#4
0
        public void ChangeHeight(UltravioletContext context, int height)
        {
            Ultraviolet.Graphics.Viewport viewport = Ultraviolet.GetGraphics().GetViewport();

            viewport.Height = height;
            context.GetGraphics().SetViewport(viewport);
        }
示例#5
0
        public void ChangeMinDepth(UltravioletContext context, int Mindepth)
        {
            Ultraviolet.Graphics.Viewport viewport = Ultraviolet.GetGraphics().GetViewport();

            viewport.MinDepth = Mindepth;
            context.GetGraphics().SetViewport(viewport);
        }
示例#6
0
        /// <inheritdoc/>
        public void RegisterImportersAndProcessors(IEnumerable <Assembly> additionalAssemblies)
        {
            Contract.EnsureNot(registered, UltravioletStrings.ContentHandlersAlreadyRegistered);

            var asmUltravioletCore = typeof(UltravioletContext).Assembly;
            var asmUltravioletImpl = Ultraviolet.GetType().Assembly;

            var asmUltravioletPlatform = Ultraviolet.GetPlatform().GetType().Assembly;
            var asmUltravioletContent  = Ultraviolet.GetContent().GetType().Assembly;
            var asmUltravioletGraphics = Ultraviolet.GetGraphics().GetType().Assembly;
            var asmUltravioletAudio    = Ultraviolet.GetAudio().GetType().Assembly;
            var asmUltravioletInput    = Ultraviolet.GetInput().GetType().Assembly;
            var asmUltravioletUI       = Ultraviolet.GetUI().GetType().Assembly;

            var assemblies = new[] {
                asmUltravioletCore,
                asmUltravioletImpl,
                asmUltravioletPlatform,
                asmUltravioletContent,
                asmUltravioletGraphics,
                asmUltravioletAudio,
                asmUltravioletInput,
                asmUltravioletUI
            }.Union(additionalAssemblies ?? Enumerable.Empty <Assembly>()).Where(x => x != null).Distinct();

            foreach (var asm in assemblies)
            {
                importers.RegisterAssembly(asm);
                processors.RegisterAssembly(asm);
            }

            registered = true;
        }
示例#7
0
        protected override void OnLoadingContent()
        {
            //TODO: Attach & Detach Window & Apply changes
            var gfx = Ultraviolet.GetGraphics();

            Ultraviolet.GetPlatform().Windows.GetPrimary().Caption = "Project Spark Test";
            Ultraviolet.GetPlatform().Windows.GetPrimary().ClientSize = new Size2(1280, 720);
            camera   = new Camera();
            _content = ContentManager.Create("Content");
            Resources.ContentManager = _content;
            LoadInputBindings();
            Resources.Input = Ultraviolet.GetInput();
            Resources.gfx   = Ultraviolet.GetGraphics();
            tr = new TextRenderer();
            tr.RegisterGlyphShader("shaky", new Shaky());
            tr.RegisterGlyphShader("wavy", new Wavy());
            spriteBatch = SpriteBatch.Create();

            LoadContentManifests();
            base.OnLoadingContent();

            Anonymous = _content.Load <SpriteFont>(GlobalFontID.Anonymous16);
            Rabelo    = _content.Load <SpriteFont>(GlobalFontID.Rabelo16);
            Trebuchet = _content.Load <SpriteFont>(GlobalFontID.TrebuchetMS16);

            States.Push(new MainMenuState());
        }
示例#8
0
        public void MoveCameraHeight(UltravioletContext context, int height)
        {
            Ultraviolet.Graphics.Viewport viewport = Ultraviolet.GetGraphics().GetViewport();

            viewport.Height = viewport.Height + height;
            context.GetGraphics().SetViewport(viewport);
        }
示例#9
0
        /// <inheritdoc/>
        public override void DrawAndSwap(UltravioletTime time,
                                         Action <UltravioletContext, UltravioletTime, IUltravioletWindow> onWindowDrawing,
                                         Action <UltravioletContext, UltravioletTime, IUltravioletWindow> onWindowDrawn)
        {
            var graphics = (OpenGLUltravioletGraphics)Ultraviolet.GetGraphics();
            var platform = Ultraviolet.GetPlatform();

            var glenv     = graphics.OpenGLEnvironment;
            var glcontext = graphics.OpenGLContext;

            foreach (var window in platform.Windows)
            {
                glenv.DesignateCurrentWindow(window, glcontext);

                window.Compositor.BeginFrame();
                window.Compositor.BeginContext(CompositionContext.Scene);

                onWindowDrawing?.Invoke(Ultraviolet, time, window);

                glenv.DrawFramebuffer(time);

                onWindowDrawn?.Invoke(Ultraviolet, time, window);

                window.Compositor.Compose();
                window.Compositor.Present();

                glenv.SwapFramebuffers();
            }

            glenv.DesignateCurrentWindow(null, glcontext);

            graphics.SetRenderTargetToBackBuffer();
            graphics.UpdateFrameCount();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicTextureAtlas"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="width">The width of the texture atlas in pixels.</param>
        /// <param name="height">The height of the texture atlas in pixels.</param>
        /// <param name="spacing">The number of pixels between cells on the texture atlas.</param>
        /// <param name="options">The texture's configuration options.</param>
        private DynamicTextureAtlas(UltravioletContext uv, Int32 width, Int32 height, Int32 spacing, TextureOptions options)
            : base(uv)
        {
            Contract.EnsureRange(width > 0, nameof(width));
            Contract.EnsureRange(height > 0, nameof(height));
            Contract.EnsureRange(spacing >= 0, nameof(spacing));

            var isSrgb   = (options & TextureOptions.SrgbColor) == TextureOptions.SrgbColor;
            var isLinear = (options & TextureOptions.LinearColor) == TextureOptions.LinearColor;

            if (isSrgb && isLinear)
            {
                throw new ArgumentException(UltravioletStrings.TextureCannotHaveMultipleEncodings);
            }

            var caps        = uv.GetGraphics().Capabilities;
            var srgbEncoded = (isLinear ? false : (isSrgb ? true : uv.Properties.SrgbDefaultForTexture2D)) && caps.SrgbEncodingEnabled;
            var surfOptions = (srgbEncoded ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor);

            this.IsFlipped = Ultraviolet.GetGraphics().Capabilities.FlippedTextures;

            this.Width   = width;
            this.Height  = height;
            this.Spacing = spacing;
            this.Surface = Surface2D.Create(width, height, surfOptions);
            this.Texture = Texture2D.CreateDynamicTexture(width, height, options, this, (dt2d, state) =>
            {
                ((DynamicTextureAtlas)state).Flush();
            });

            Clear(true);
            Invalidate();
        }
示例#11
0
        /// <summary>
        /// Generates vertices for a group of sprites.
        /// </summary>
        /// <param name="texture">The batch's texture.</param>
        /// <param name="sprites">The batch's sprite metadata array.</param>
        /// <param name="vertices">The batch's vertex data array.</param>
        /// <param name="data">The batch's custom data array.</param>
        /// <param name="offset">The offset of the first sprite being drawn.</param>
        /// <param name="count">The number of sprites being drawn.</param>
        /// <returns>The vertex stride.</returns>
        protected override unsafe void GenerateVertices(Texture2D texture, SpriteHeader[] sprites,
                                                        SpriteVertex[] vertices, SpriteBatchData[] data, Int32 offset, Int32 count)
        {
            var srgb = Ultraviolet.GetGraphics().CurrentRenderTargetIsSrgbEncoded;

            fixed(SpriteHeader *pSprites1 = &sprites[offset])
            fixed(SpriteBatchData * pData1  = &data[offset])
            fixed(SpriteVertex * pVertices1 = &vertices[0])
            {
                var pSprites  = pSprites1;
                var pData     = pData1;
                var pVertices = pVertices1;

                for (int i = 0; i < count; i++)
                {
                    CalculateSinAndCos(pSprites->Rotation);
                    CalculateRelativeOrigin(pSprites);

                    for (int v = 0; v < 4; v++)
                    {
                        CalculatePositionAndTextureCoordinates(pSprites, v,
                                                               (Vector2 *)&pVertices->Position, &pVertices->U, &pVertices->V);

                        pVertices->Color = pSprites->Color;// srgb ? Color.ConvertSrgbColorToLinear(pSprites->Color) : pSprites->Color;
                        pVertices++;
                    }

                    pSprites++;
                    pData++;
                }
            }
        }
示例#12
0
        /// <inheritdoc/>
        protected override void DrawOverride(UltravioletTime time, DrawingContext dc)
        {
            DrawBlank(dc, Color.Black * 0.5f);

            var viewport = AdjustViewportFor3D(dc);

            var triangleRotation    = TriangleRotation;
            var triangleDistance    = 5f - (TriangleZoom * 2.5f);
            var triangleAspectRatio = (Single)(ActualWidth / ActualHeight);

            var gfx    = Ultraviolet.GetGraphics();
            var effect = EnsureEffect();

            effect.World              = Matrix.CreateRotationY(TriangleRotation);
            effect.View               = Matrix.CreateLookAt(new Vector3(0, 0, triangleDistance), Vector3.Zero, Vector3.Up);
            effect.Projection         = Matrix.CreatePerspectiveFieldOfView((Single)(Math.PI / 4.0), triangleAspectRatio, 1f, 1000f);
            effect.VertexColorEnabled = true;

            foreach (var pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                gfx.SetRasterizerState(RasterizerState.CullNone);
                gfx.SetGeometryStream(EnsureGeometryStream());
                gfx.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
            }

            gfx.SetViewport(viewport);

            base.DrawOverride(time, dc);
        }
        /// <inheritdoc/>
        public override Texture2D CreateTexture(Boolean unprocessed)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            if (unprocessed)
            {
                var options = TextureOptions.ImmutableStorage | (SrgbEncoded ? TextureOptions.SrgbColor : TextureOptions.LinearColor);
                return(Texture2D.CreateTexture((IntPtr)NativePtr->pixels, Width, Height, BytesPerPixel, options));
            }
            else
            {
                using (var copysurf = new SDL2PlatformNativeSurface(Width, Height))
                {
                    if (SDL_BlitSurface(nativesurf.NativePtr, null, copysurf.NativePtr, null) < 0)
                    {
                        throw new SDL2Exception();
                    }

                    copysurf.Flip(Ultraviolet.GetGraphics().Capabilities.FlippedTextures ?
                                  SurfaceFlipDirection.Vertical : SurfaceFlipDirection.None);

                    var options = TextureOptions.ImmutableStorage | (SrgbEncoded ? TextureOptions.SrgbColor : TextureOptions.LinearColor);
                    return(Texture2D.CreateTexture((IntPtr)copysurf.NativePtr->pixels, copysurf.Width, copysurf.Height, copysurf.BytesPerPixel, options));
                }
            }
        }
示例#14
0
        /// <summary>
        /// Called when the scene is being rendered.
        /// </summary>
        /// <param name="time">Time elapsed since the last call to Draw.</param>
        protected override void OnDrawing(UltravioletTime time)
        {
            spriteBatch.Begin();

            //player sprite draw
            spriteBatch.DrawSprite(this.playerObj.animations[this.playerObj.animationIndex], this.playerObj.position);

            //if a bullet is being fired, draw it
            if (firingBullet)
            {
                spriteBatch.DrawSprite(this.firedBullet.animations[this.firedBullet.animationIndex], this.firedBullet.position);
            }

            textFormatter.Reset();
            textFormatter.AddArgument(Ultraviolet.GetGraphics().FrameRate);
            textFormatter.AddArgument(GC.GetTotalMemory(false) / 1024);
            textFormatter.AddArgument(Environment.Is64BitProcess ? "64-bit" : "32-bit");
            textFormatter.Format("{0:decimals:2} FPS\nAllocated: {1:decimals:2} kb\n{2}", textBuffer);

            spriteBatch.DrawString(spriteFont, textBuffer, Vector2.One * 8f, TwistedLogik.Ultraviolet.Color.White);

            var size     = Ultraviolet.GetPlatform().Windows.GetCurrent().ClientSize;
            var settings = new TextLayoutSettings(spriteFont, size.Width, size.Height, TextFlags.AlignCenter | TextFlags.AlignMiddle);

            textRenderer.Draw(spriteBatch, "Welcome to the |c:FFFF00C0|Ultraviolet Framework|c|!", Vector2.Zero, TwistedLogik.Ultraviolet.Color.White, settings);

            //physicsTestObject.DrawObject(spriteBatch, true, textRenderer, settings);
            groundTestObject.DrawObject(spriteBatch, true, textRenderer, settings);

            spriteBatch.End();

            base.OnDrawing(time);
        }
示例#15
0
        /// <summary>
        /// Releases resources associated with the object.
        /// </summary>
        /// <param name="disposing">true if the object is being disposed; false if the object is being finalized.</param>
        protected override void Dispose(Boolean disposing)
        {
            if (Disposed)
            {
                return;
            }

            if (disposing)
            {
                if (!Ultraviolet.Disposed)
                {
                    ((OpenGLUltravioletGraphics)Ultraviolet.GetGraphics()).UnbindTexture(this);
                }

                if (willNotBeSampled)
                {
                    if (!Ultraviolet.Disposed && renderbuffer != 0)
                    {
                        Ultraviolet.QueueWorkItem((state) =>
                        {
                            gl.DeleteRenderBuffers(((OpenGLRenderBuffer2D)state).renderbuffer);
                            gl.ThrowIfError();
                        }, this);
                    }
                }
                else
                {
                    SafeDispose.Dispose(texture);
                }
            }

            base.Dispose(disposing);
        }
示例#16
0
        /// <inheritdoc/>
        protected override void OnDrawing(UltravioletTime time)
        {
            // We specify that we want to start drawing to a render target with the SetRenderTarget() method.
            Ultraviolet.GetGraphics().SetRenderTarget(rtarget);

            // IMPORTANT NOTE!
            // When a render target is set for rendering, Ultraviolet will automatically clear it to a lovely shade of dark purple.
            // You can change this behavior by passing RenderTargetUsage.PreserveContents to the render target constructor.
            Ultraviolet.GetGraphics().Clear(Color.Black);

            var effect     = content.Load <Effect>(GlobalEffectID.Noise);
            var effectTime = (Single)time.TotalTime.TotalSeconds * 0.1f;

            effect.Parameters["time"].SetValue(effectTime);

            var blank = content.Load <Texture2D>(GlobalTextureID.Blank);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, effect);
            spriteBatch.Draw(blank, new RectangleF(0, 0, rtarget.Width, rtarget.Height), Color.White);
            spriteBatch.End();

            // When we finish drawing to a render target, we can revert to the compositor target by passing
            // null to the SetRenderTarget() method.
            Ultraviolet.GetGraphics().SetRenderTarget(null);
            Ultraviolet.GetGraphics().Clear(Color.CornflowerBlue);

            // IMPORTANT NOTE!
            // A render target (including its buffers) CANNOT BE BOUND FOR READING AND WRITING SIMULTANEOUSLY.
            // You MUST revert to a different render target before trying to draw your buffers!
            var compositor = Ultraviolet.GetPlatform().Windows.GetPrimary().Compositor;
            var compWidth  = compositor.Width;
            var compHeight = compositor.Height;

            var font = content.Load <SpriteFont>(GlobalFontID.SegoeUI);

            spriteBatch.Begin(SpriteSortMode.Deferred, null);
            spriteBatch.Draw(rbufferColor, new Vector2(
                                 (compWidth - rbufferColor.Width) / 2,
                                 (compHeight - rbufferColor.Height) / 2), Color.White);

            var instruction = Ultraviolet.Platform == UltravioletPlatform.Android ?
                              "Tap to save the image to the gallery" :
                              "Press F1 to save the image to a file";

            spriteBatch.DrawString(font, instruction,
                                   new Vector2(8f, 8f), Color.White);
            spriteBatch.DrawString(font, confirmMsgText ?? String.Empty,
                                   new Vector2(8f, 8f + font.Regular.LineSpacing), Color.White * (Single)confirmMsgOpacity);

            spriteBatch.End();

            // IMPORTANT NOTE!
            // Remember, we can't be bound for both reading and writing. We're currently bound for reading,
            // so we need to remember to unbind our buffers before we write to them again in the next frame.
            // The UnbindTexture() method is provided for convenience; if you know which sampler your texture
            // is bound to, you can either unbind the sampler manually, or bind another texture to it using SetTexture().
            Ultraviolet.GetGraphics().UnbindTexture(rbufferColor);

            base.OnDrawing(time);
        }
        /// <inheritdoc/>
        public override Texture3D CreateTexture(Boolean unprocessed)
        {
            Contract.EnsureNotDisposed(this, Disposed);
            Contract.Ensure(IsComplete, SDL2Strings.SurfaceIsNotComplete);

            EnsureAllLayersMatchSrgbEncoding();

            var copysurfs = new Surface2D[Depth];
            var surfsdata = new IntPtr[Depth];

            try
            {
                var flipdir = unprocessed ? SurfaceFlipDirection.None :
                              (Ultraviolet.GetGraphics().Capabilities.FlippedTextures ? SurfaceFlipDirection.Vertical : SurfaceFlipDirection.None);

                for (int i = 0; i < copysurfs.Length; i++)
                {
                    copysurfs[i] = layers[i].CreateSurface();
                    copysurfs[i].FlipAndProcessAlpha(flipdir, false, Color.Magenta);
                    surfsdata[i] = (IntPtr)((SDL2Surface2D)copysurfs[i]).NativePtr->pixels;
                }

                var options = TextureOptions.ImmutableStorage | (SrgbEncoded ? TextureOptions.SrgbColor : TextureOptions.LinearColor);
                return(Texture3D.CreateTexture(surfsdata, Width, Height, BytesPerPixel, options));
            }
            finally
            {
                foreach (var copysurf in copysurfs)
                {
                    copysurf?.Dispose();
                }
            }
        }
        /// <inheritdoc/>
        protected override void Dispose(Boolean disposing)
        {
            if (Disposed)
            {
                return;
            }

            if (disposing)
            {
                var glname = texture;
                if (glname != 0 && !Ultraviolet.Disposed)
                {
                    ((OpenGLUltravioletGraphics)Ultraviolet.GetGraphics()).UnbindTexture(this);
                    Ultraviolet.QueueWorkItem((state) =>
                    {
                        gl.DeleteTexture(glname);
                        gl.ThrowIfError();
                    }, this, WorkItemOptions.ReturnNullOnSynchronousExecution);
                }

                texture = 0;
            }

            base.Dispose(disposing);
        }
示例#19
0
        /// <summary>
        /// Initializes the font texture atlas for the current ImGui context.
        /// </summary>
        private void InitFontTextureAtlas()
        {
            unsafe
            {
                var io = ImGui.GetIO();

                io.Fonts.GetTexDataAsRGBA32(out var textureData,
                                            out var textureWidth, out var textureHeight, out var textureBytesPerPixel);

                var srgb = Ultraviolet.GetGraphics().Capabilities.SrgbEncodingEnabled;

                var surfaceOptions = srgb ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor;
                var surface        = Surface2D.Create(textureWidth, textureHeight, surfaceOptions);
                surface.SetRawData((IntPtr)textureData, 0, 0, textureWidth * textureHeight);
                surface.Flip(SurfaceFlipDirection.Vertical);

                var textureOptions = TextureOptions.ImmutableStorage | (srgb ? TextureOptions.SrgbColor : TextureOptions.LinearColor);
                var texture        = Texture2D.CreateTexture(textureWidth, textureHeight, textureOptions);
                texture.SetData(surface);

                fontAtlasID = Textures.Register(texture);

                io.Fonts.SetTexID(new IntPtr(fontAtlasID));
                io.Fonts.ClearTexData();
            }
        }
示例#20
0
        /// <inheritdoc/>
        protected override void OnDrawing(UltravioletTime time)
        {
            var fps = Ultraviolet.GetGraphics().FrameRate;

            Array.Copy(fpsHistory, 1, fpsHistory, 0, fpsHistory.Length - 1);
            fpsHistory[fpsHistory.Length - 1] = fps;

            var gfx            = Ultraviolet.GetGraphics();
            var window         = Ultraviolet.GetPlatform().Windows.GetPrimary();
            var drawableWidth  = window.DrawableSize.Width;
            var drawableHeight = window.DrawableSize.Height;
            var aspectRatio    = drawableWidth / (float)drawableHeight;

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            for (int i = 0; i < 5000; i++)
            {
                var x = rng.Next(drawableWidth);
                var y = rng.Next(drawableHeight);
                spriteBatch.DrawSprite(sprite[rng.Next(sprite.AnimationCount)].Controller, new Vector2(x, y));
            }
            spriteBatch.End();

            effect.World              = Matrix.CreateRotationY((float)(2.0 * Math.PI * time.TotalTime.TotalSeconds));
            effect.View               = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up);
            effect.Projection         = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4f, aspectRatio, 1f, 1000f);
            effect.VertexColorEnabled = true;

            foreach (var pass in this.effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                gfx.SetRasterizerState(RasterizerState.CullNone);
                gfx.SetGeometryStream(geometryStream);
                gfx.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
            }

            strFormatter.Reset();
            strFormatter.AddArgument(fps);
            strFormatter.Format("{0:decimals:2}", strBuffer);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            for (int i = 0; i < fpsHistory.Length; i++)
            {
                var historyFps    = fpsHistory[i];
                var historyWidth  = drawableWidth / fpsHistory.Length;
                var historyHeight = (Int32)(historyFps * 2.0);
                var historyX      = i * historyWidth;
                var historyY      = drawableHeight - historyHeight;
                var historyColor  = historyFps < 55 ? (historyFps < 40 ? Color.Red : Color.Yellow) : Color.Lime;
                spriteBatch.Draw(blankTexture, new RectangleF(historyX, historyY, historyWidth, historyHeight), historyColor * 0.5f);
            }
            spriteBatch.Draw(blankTexture, new RectangleF(0, drawableHeight - 120, drawableWidth, 1), Color.White);
            spriteBatch.DrawString(spriteFont, strBuffer, Vector2.Zero, Color.White);

            spriteBatch.End();

            base.OnDrawing(time);
        }
        /// <summary>
        /// Draws the contents of the vertex and index buffer.
        /// </summary>
        private void DrawBuffers(ref ImDrawDataPtr drawDataPtr)
        {
            EnsureBuffers(ref drawDataPtr);

            var gfx = Ultraviolet.GetGraphics();

            gfx.SetGeometryStream(geometryStream);
            gfx.SetBlendState(BlendState.NonPremultiplied);
            gfx.SetDepthStencilState(DepthStencilState.None);
            gfx.SetRasterizerState(rasterizerState);
            gfx.SetSamplerState(0, SamplerState.LinearClamp);

            for (var i = 0; i < drawDataPtr.CmdListsCount; i++)
            {
                var cmdList = drawDataPtr.CmdListsRange[i];

                this.vertexBuffer.SetRawData(cmdList.VtxBuffer.Data, 0, 0,
                                             cmdList.VtxBuffer.Size * sizeof(ImGuiVertex), SetDataOptions.Discard);

                this.indexBuffer.SetRawData(cmdList.IdxBuffer.Data, 0, 0,
                                            cmdList.IdxBuffer.Size * sizeof(UInt16), SetDataOptions.Discard);

                var idxOffset = 0;

                for (int j = 0; j < cmdList.CmdBuffer.Size; j++)
                {
                    var cmd = cmdList.CmdBuffer[j];

                    gfx.SetScissorRectangle(
                        (Int32)cmd.ClipRect.X,
                        (Int32)cmd.ClipRect.Y,
                        (Int32)(cmd.ClipRect.Z - cmd.ClipRect.X),
                        (Int32)(cmd.ClipRect.W - cmd.ClipRect.Y));

                    var texture = view.Textures.Get((Int32)cmd.TextureId);
                    if (texture != null)
                    {
                        effect.SrgbColor       = gfx.Capabilities.SrgbEncodingEnabled;
                        effect.Texture         = texture;
                        effect.TextureSize     = new Size2(1, 1);
                        effect.MatrixTransform = Matrix.CreateOrthographicOffCenter(0,
                                                                                    ImGui.GetIO().DisplaySize.X,
                                                                                    ImGui.GetIO().DisplaySize.Y, 0, 0, 1);

                        foreach (var pass in effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            gfx.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, idxOffset, (Int32)cmd.ElemCount / 3);
                        }
                    }

                    idxOffset += (Int32)cmd.ElemCount;
                }
            }

            gfx.SetRasterizerState(RasterizerState.CullCounterClockwise);
        }
示例#22
0
        /// <inheritdoc/>
        public override void BeginFrame()
        {
            Contract.EnsureNotDisposed(this, Disposed);

            var window   = Ultraviolet.GetPlatform().Windows.GetCurrent();
            var graphics = Ultraviolet.GetGraphics();

            graphics.SetRenderTarget(null);
            graphics.SetViewport(new Viewport(0, 0, window.DrawableSize.Width, window.DrawableSize.Height));
            graphics.Clear(Color.CornflowerBlue, 1.0f, 0);
        }
示例#23
0
        /// <inheritdoc/>
        public override void BeginFrame()
        {
            var gfx = Ultraviolet.GetGraphics();

            gfx.SetRenderTarget(rtComposition);
            gfx.Clear(Color.Transparent, 1.0f, 0);

            gfx.SetRenderTarget(rtScene);
            gfx.Clear(Color.Transparent, 1.0f, 0);

            base.BeginFrame();
        }
示例#24
0
        /// <inheritdoc/>
        public override Int32 GetAlignedSize(Int32 count)
        {
            Contract.EnsureRange(count >= 0, nameof(count));

            var caps = (OpenGLGraphicsCapabilities)Ultraviolet.GetGraphics().Capabilities;

            if (caps.MinMapBufferAlignment == 0 || count == VertexCount)
            {
                return(count * vdecl.VertexStride);
            }
            return(Math.Max(caps.MinMapBufferAlignment, MathUtil.FindNextPowerOfTwo(count * vdecl.VertexStride)));
        }
示例#25
0
        /// <summary>
        /// Handles the Drawing event for ultravioletPanel2.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">An EventArgs that contains the event data.</param>
        private void ultravioletPanel2_Drawing(object sender, EventArgs e)
        {
            Ultraviolet.GetGraphics().Clear(Color.Black);

            spriteBatch.Begin();

            var size     = Ultraviolet.GetPlatform().Windows.GetCurrent().Compositor.Size;
            var settings = new TextLayoutSettings(spriteFont, size.Width, size.Height, TextFlags.AlignCenter | TextFlags.AlignMiddle);

            textRenderer.Draw(spriteBatch, "This is a |c:FF00FF00|secondary tool window|c|.", Vector2.Zero, Color.White, settings);

            spriteBatch.End();
        }
示例#26
0
        protected override void OnDrawing(UltravioletTime time)
        {
            var gfx = Ultraviolet.GetGraphics();

            gfx.Clear(new Color(222, 206, 206));
            var viewMatrix = camera.GetTransform();

            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, null, viewMatrix * Matrix.CreateScale(screenScale));
            _current.Draw(spriteBatch);
            var settings = new TextLayoutSettings(Trebuchet, null, null, TextFlags.Standard);

            tr.Draw(spriteBatch, "|shader:wavy|Hallo Welt ich teste gerade |shader:shaky|glyph shaders|shader| !!!", new Vector2(100, 100), Color.White, settings);
            spriteBatch.End();
            base.OnDrawing(time);
        }
示例#27
0
        /// <inheritdoc/>
        public override Int32 GetAlignedSize(Int32 count)
        {
            Contract.EnsureRange(count >= 0, nameof(count));
            Contract.EnsureNotDisposed(this, Disposed);

            var indexStride = GetElementSize();

            var caps = (OpenGLGraphicsCapabilities)Ultraviolet.GetGraphics().Capabilities;

            if (caps.MinMapBufferAlignment == 0 || count == IndexCount)
            {
                return(count * indexStride);
            }

            return(Math.Max(caps.MinMapBufferAlignment, MathUtil.FindNextPowerOfTwo(count * indexStride)));
        }
示例#28
0
        /// <summary>
        /// Called when the application's scene is being drawn.
        /// </summary>
        /// <param name="time">Time elapsed since the last call to Draw.</param>
        protected override void OnDrawing(UltravioletTime time)
        {
            var gfx         = Ultraviolet.GetGraphics();
            var window      = Ultraviolet.GetPlatform().Windows.GetCurrent();
            var aspectRatio = window.DrawableSize.Width / (Single)window.DrawableSize.Height;

            effect.World      = Matrix.CreateRotationY((float)(2.0 * Math.PI * (time.TotalTime.TotalSeconds / 10.0)));
            effect.View       = Matrix.CreateLookAt(new Vector3(0, 3, 6), new Vector3(0, 0.75f, 0), Vector3.Up);
            effect.Projection = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4f, aspectRatio, 1f, 1000f);

            gfx.SetGeometryStream(geometryStream);

            void DrawGeometry(RasterizerState rasterizerState, DepthStencilState depthStencilState)
            {
                foreach (var pass in this.effect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    gfx.SetRasterizerState(rasterizerState);
                    gfx.SetDepthStencilState(depthStencilState);
                    gfx.DrawPrimitives(PrimitiveType.TriangleList, 0, vertexBuffer.VertexCount / 3);
                    //gfx.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indexBuffer.IndexCount / 3);
                }
            }

            effect.FogColor = Color.Red;
            effect.PreferPerPixelLighting = true;
            effect.LightingEnabled        = true;
            effect.SrgbColor          = false;
            effect.VertexColorEnabled = false;
            effect.DiffuseColor       = Color.White;
            effect.TextureEnabled     = false;
            effect.Texture            = texture;
            DrawGeometry(rasterizerStateSolid, DepthStencilState.Default);

            if (!gl.IsGLES)
            {
                effect.LightingEnabled    = false;
                effect.FogEnabled         = false;
                effect.VertexColorEnabled = false;
                effect.DiffuseColor       = Color.Black;
                effect.TextureEnabled     = false;
                DrawGeometry(rasterizerStateWireframe, DepthStencilState.None);
            }

            base.OnDrawing(time);
        }
示例#29
0
        /// <inheritdoc/>
        public override void Present()
        {
            var gfx = Ultraviolet.GetGraphics();

            gfx.SetRenderTarget(TestFrameworkRenderTarget);
            gfx.Clear(Color.Black, 1.0f, 0);

            var area = new RectangleF(0, 0,
                                      Window.DrawableSize.Width, Window.DrawableSize.Height);

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
            spriteBatch.Draw(rtCompositionColor, area, Color.White);
            spriteBatch.End();

            gfx.UnbindTexture(rtCompositionColor);

            base.Present();
        }
示例#30
0
        /// <inheritdoc/>
        public override void Compose()
        {
            var gfx = Ultraviolet.GetGraphics();

            gfx.SetRenderTarget(rtComposition);

            var area = new RectangleF(0, 0,
                                      rtComposition.Width, rtComposition.Height);

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
            spriteBatch.Draw(rtSceneColor, area, Color.Red);
            spriteBatch.Draw(rtInterfaceColor, area, Color.Lime);
            spriteBatch.End();

            gfx.UnbindTexture(rtSceneColor);
            gfx.UnbindTexture(rtInterfaceColor);

            base.Compose();
        }