Exemplo n.º 1
0
        /// <summary>
        /// Creates a client window.
        /// </summary>
        public RootWindow(GraphicsDevice graphicsDevice, IWindowManager windowManager, string title, string titleGroup,
                          WindowOptions windowOptions, Vector2i position, Vector2i size, Vector2i?minSize, Vector2i?maxSize,
                          WindowState windowState, IWidget widget, uint multisampleCount, uint multisampleQuality)
        {
            // 1) Copy data.
            this.graphicsDevice = graphicsDevice;

            // 2) We create render target.
            TypelessTexture2D texture = new TypelessTexture2D(graphicsDevice, Usage.Default, TextureUsage.RenderTarget | TextureUsage.Texture,
                                                              CPUAccess.None, PixelFormat.Parse("R.UN8 G.UN8 B.UN8 A.UN8"), (uint)size.X, (uint)size.Y, 1,
                                                              multisampleCount, multisampleQuality, GraphicsLocality.DeviceOrSystemMemory, null);

            texture.DisposeOnViewDispose = true;

            Guid shareGuid = graphicsDevice.RegisterShared(texture, TextureUsage.Texture);

            RenderTargetView renderTarget = texture.CreateRenderTarget(
                PixelFormat.Parse("R.UN8 G.UN8 B.UN8 A.UN8"));

            window = windowManager.CreateWindow(shareGuid, title, titleGroup, this, windowOptions,
                                                position, size, minSize, maxSize, windowState, null, false);

            // 3) We create graphics canvas.
            GraphicsCanvas canvas = new GraphicsCanvas(graphicsDevice, renderTarget, new Vector2f(1, 1));

            // 4) We create GUI manager.
            GuiManager manager = new GuiManager(canvas);

            manager.RootObject    = widget;
            manager.PreRendering += new Action <GuiManager>(PreRenderingInternal);
            manager.Rendered     += new Action <GuiManager>(RenderedInternal);

            this.root = manager;
        }
Exemplo n.º 2
0
        TextureView CreateSampleTexture()
        {
            // Non-mipmapped.
            TypelessTexture2D texture = new TypelessTexture2D(Usage.Default,
                                                              TextureUsage.Texture, CPUAccess.None, PixelFormat.Parse("R.UN8 G.UN8 B.UN8 A.UN8"),
                                                              512, 512, 1, GraphicsLocality.DeviceOrSystemMemory, null);

            // We create data.
            byte[] data = texture.Map(MapOptions.Write, 0).Data;
            for (int x = 0; x < 512; x++)
            {
                for (int y = 0; y < 512; y++)
                {
                    int idx = (y * 512 + x) * 4;
                    data[idx]     = (byte)((x * 256) / 512);
                    data[idx + 1] = (byte)((y * 256) / 512);
                    data[idx + 2] = (byte)(((x + y) * 256) / 1024);
                    data[idx + 3] = 100;  // Semi-Transparent
                }
            }
            texture.UnMap(0);

            texture.DisposeOnViewDispose = true;

            return(texture.CreateTexture());
        }
        void Dispose(bool fromFinalizer)
        {
            if (cacheableState == SharpMedia.Caching.CacheableState.Disposed)
            {
                return;
            }

            cacheableState = SharpMedia.Caching.CacheableState.Disposed;
            texture2D.Release();

            if (!fromFinalizer)
            {
                GC.SuppressFinalize(this);
                texture2D = null;
            }


            // We fire events.
            Action <IResource> r = onDisposed;

            if (r != null)
            {
                r(this);
            }
        }
Exemplo n.º 4
0
        internal TypelessTexture2DAsRenderTarget(TypelessTexture2D texture, PixelFormat fmt, uint mipmapSlice)
        {
            this.texture     = texture;
            this.mipmapSlice = mipmapSlice;
            this.format      = fmt;

            texture.AddRef();
        }
Exemplo n.º 5
0
        internal TypelessTexture2DAsRenderTarget(TypelessTexture2D texture, PixelFormat fmt)
        {
            this.texture     = texture;
            this.format      = fmt;
            this.multisample = true;

            texture.AddRef();
        }
        internal TypelessTexture2DAsDepthStencil(TypelessTexture2D texture, PixelFormat fmt)
        {
            this.texture     = texture;
            this.format      = fmt;
            this.multisample = true;

            texture.AddRef();
        }
        internal TypelessTexture2DAsDepthStencil(TypelessTexture2D texture, PixelFormat fmt, uint mipmap)
        {
            this.texture = texture;
            this.format  = fmt;
            this.mipmap  = mipmap;

            texture.AddRef();
        }
        internal TypelessTexture2DAsTexture2D(PixelFormat format,
                                              uint mostDetailed, uint count, TypelessTexture2D texture2D)
        {
            this.format             = format;
            this.mostDetailedMipmap = mostDetailed;
            this.mipmapCount        = count;
            this.texture2D          = texture2D;

            // We try to bind to device.
            if (this.texture2D.Device != null)
            {
                // We bind to device.
                BindToDevice(texture2D.Device);
            }
        }
        public override Image CloneSameType(PixelFormat fmt, uint width, uint height,
                                            uint depth, uint faces, uint mipmaps)
        {
            lock (syncRoot)
            {
                AssertNotDisposed();

                // We clone the same image and the view.
                TypelessTexture2D baseTexture = texture2D.CloneSameType(fmt, width,
                                                                        height, depth, faces, mipmaps) as TypelessTexture2D;

                // And create the view (mostDetailed and mipmapCount may be clamped).
                return(baseTexture.CreateTexture(format, mostDetailedMipmap, mipmapCount));
            }
        }
Exemplo n.º 10
0
        public override Image CloneSameType(PixelFormat fmt, uint width, uint height, uint depth,
                                            uint faces, uint mipmaps)
        {
            lock (syncRoot)
            {
                AssertNotDisposed();
                TypelessTexture2D b = texture.CloneSameType(fmt, width, height, depth, faces, mipmaps) as TypelessTexture2D;

                if (multisample)
                {
                    return(new TypelessTexture2DAsRenderTarget(b, format));
                }
                else
                {
                    return(new TypelessTexture2DAsRenderTarget(b, format, mipmapSlice));
                }
            }
        }
Exemplo n.º 11
0
        void Dispose(bool fin)
        {
            // Already disposed.
            if (cacheableState == SharpMedia.Caching.CacheableState.Disposed)
            {
                return;
            }

            texture.Release();

            if (this.view != null)
            {
                view.Dispose();
            }

            if (!fin)
            {
                GC.SuppressFinalize(this);
                texture = null;
            }

            cacheableState = SharpMedia.Caching.CacheableState.Disposed;
        }
        void Dispose(bool fin)
        {
            if (disposed)
            {
                return;
            }

            disposed = true;

            if (view != null)
            {
                view.Dispose();
                view = null;
            }

            texture.Release();

            if (!fin)
            {
                GC.SuppressFinalize(this);
                texture = null;
            }
        }