Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TypelessTexture2D"/> class.
        /// </summary>
        /// <param name="usage">The usage.</param>
        /// <param name="textureUsage">The texture usage.</param>
        /// <param name="fmt">The FMT.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="dp">The dp.</param>
        public TypelessTexture2D(GraphicsDevice device, Usage usage, TextureUsage textureUsage,
                                 CPUAccess cpuAccess, PixelFormat fmt, uint width, uint height, uint mipmaps,
                                 uint sampleCount, uint sampleQuality, GraphicsLocality locality, byte[][] data)
            : base(usage, textureUsage, cpuAccess, locality)
        {
            Validate(mipmaps, width, height);
            this.width       = width;
            this.height      = height;
            this.format      = fmt;
            this.mipmapCount = mipmaps == 0 ? Images.MipmapHelper.MipmapCount(width, height) : mipmaps;

            // We create driver part.
            if (locality != GraphicsLocality.SystemMemoryOnly)
            {
                this.device     = device;
                this.driverPart = device.DriverDevice.CreateTexture2D(usage, fmt.CommonFormatLayout,
                                                                      CPUAccess, width, height, mipmaps, textureUsage, sampleCount, sampleQuality, data);
            }

            // We may need to create sw part.
            if (locality == GraphicsLocality.DeviceAndSystemMemory ||
                locality == GraphicsLocality.SystemMemoryOnly)
            {
                this.swData = data;
            }
        }
Example #2
0
        private void Dispose(bool fromFinalizer)
        {
            if (cacheableState == CacheableState.Disposed)
            {
                return;
            }
            cacheableState = CacheableState.Disposed;

            swData = null;
            if (driverPart != null)
            {
                if (sharingContext.IsOwned)
                {
                    driverPart.Dispose();
                }
                driverPart = null;
            }

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


            // We fire events.
            FireWritten();
        }
Example #3
0
        /// <summary>
        /// Creates a shared typeless texture.
        /// </summary>
        internal TypelessTexture2D(GraphicsDevice device, Driver.SharedTextureInfo info, Guid guid)
            : base(info.Usage, info.TextureUsage, CPUAccess.None, GraphicsLocality.DeviceMemoryOnly)
        {
            this.width       = info.Width;
            this.height      = info.Height;
            this.format      = info.Format;
            this.mipmapCount = info.Mipmaps;

            this.sharingContext = new SharingContext(guid);

            // We get shared.
            this.driverPart = info.Texture as Driver.ITexture2D;
        }
Example #4
0
        void ReleaseDriverPart()
        {
            device = null;
            if (driverPart != null)
            {
                if (sharingContext.IsShared)
                {
                    throw new InvalidOperationException("Unbinding device that is shared and owned.");
                }

                driverPart.Dispose();
                driverPart = null;
            }
        }
Example #5
0
        public override void BindToDevice(GraphicsDevice device)
        {
            lock (syncRoot)
            {
                AssertNotDisposed();
                AssertNotLocked();

                this.device = device;
                if (driverPart == null)
                {
                    if (sharingContext.IsOwned)
                    {
                        driverPart = device.DriverDevice.CreateTexture2D(usage, Format.CommonFormatLayout,
                                                                         this.CPUAccess, width, height, mipmapCount, textureUsage, 1, 0, swData);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
        }