private bool Initialize(TextureManager manager, D3d.Format format, int size, bool mipmap, int multisample)
        {
            D3d.Pool  d3dPool  = D3d.Pool.Default;
            D3d.Usage d3dUsage = manager.GetUsageFlags(false, mipmap, true);

            try
            {
                d3dTexture = new D3d.CubeTexture(manager.Device.D3dDevice, size, manager.GetMipLevelCount(mipmap), d3dUsage, format, d3dPool);

                // Create depth buffer.
                d3dDepthBuffer = manager.Device.D3dDevice.CreateDepthStencilSurface(size, size, manager.Device.Settings.depthBufferFormat, (D3d.MultiSampleType)multisample, 0, true);

                this.Initialize(manager, format, size, size, 6, d3dTexture);

                return(true);
            }
            catch (D3d.InvalidCallException e)
            {
                log.Warning("Unable to create render cube texture: {0}", e.Message);
            }
            catch (D3d.OutOfVideoMemoryException e)
            {
                log.Warning("Unable to create render cube texture: {0}", e.Message);
            }
            catch (OutOfMemoryException e)
            {
                log.Warning("Unable to create render cube texture: {0}", e.Message);
            }

            return(false);
        }
예제 #2
0
        private bool Initialize(TextureManager manager, D3d.Format format, int width, int height, int depth, bool dynamic, bool mipmap)
        {
            D3d.Pool  d3dPool  = D3d.Pool.Managed;
            D3d.Usage d3dUsage = manager.GetUsageFlags(dynamic, mipmap, false);

            try
            {
                d3dTexture = new D3d.VolumeTexture(manager.Device.D3dDevice, width, height, depth, manager.GetMipLevelCount(mipmap), d3dUsage, format, d3dPool);
                this.Initialize(manager, format, width, height, depth, d3dTexture);

                return(true);
            }
            catch (D3d.InvalidCallException e)
            {
                log.Warning("Unable to create 3d texture: {0}", e.Message);
            }
            catch (D3d.OutOfVideoMemoryException e)
            {
                log.Warning("Unable to create 3d texture: {0}", e.Message);
            }
            catch (OutOfMemoryException e)
            {
                log.Warning("Unable to create 3d texture: {0}", e.Message);
            }

            return(false);
        }
예제 #3
0
        private bool ModifyParameters(D3d.ResourceType type,
                                      D3d.Format format,
                                      bool dynamic,
                                      bool mipmap,
                                      bool isTarget,
                                      ref int width,
                                      ref int height,
                                      ref int depth)
        {
            // First fix any dimensional errors.
            width  = width / textureDivider;
            height = height / textureDivider;
            depth  = depth / textureDivider;

            // Make sure we stay within maximum allowed dimensions.
            if (width > textureDevice.Capabilities.textureMaxWidth)
            {
                width = textureDevice.Capabilities.textureMaxWidth;
            }

            if (height > textureDevice.Capabilities.textureMaxHeight)
            {
                height = textureDevice.Capabilities.textureMaxHeight;
            }

            if (depth > textureDevice.Capabilities.textureMaxDepth)
            {
                depth = textureDevice.Capabilities.textureMaxDepth;
            }

            D3d.Usage d3dUsage = GetUsageFlags(dynamic, mipmap, isTarget);

            // Get the current display mode format for later use.
            D3d.Format displayFormat = D3d.Manager.Adapters[Device.Settings.adapterIndex].CurrentDisplayMode.Format;

            if (D3d.Manager.CheckDeviceFormat(Device.Settings.adapterIndex,
                                              Device.Settings.deviceType,
                                              Device.Settings.backBufferFormat,
                                              d3dUsage, type, format))
            {
                if (isTarget)
                {
                    if (D3d.Manager.CheckDepthStencilMatch(Device.Settings.adapterIndex,
                                                           Device.Settings.deviceType,
                                                           displayFormat,
                                                           format,
                                                           Device.Settings.depthBufferFormat))
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        /// <summary>
        /// Loads the specified image into the texture.
        /// </summary>
        /// <param name="device">The DirectX device to load the texture into.</param>
        /// <param name="image">The image to load.</param>
        /// <param name="usage">The Direct3D Usage parameter for the image.</param>
        /// <param name="pool">The Direct3D Pool parameter for the image.</param>
        public void SetImage(D3D.Device device, Bitmap image, D3D.Usage usage, D3D.Pool pool)
        {
            if (_texture != null)
            {
                _texture.Dispose();
            }

            _texture = new D3D.Texture(device, image, usage, pool);
        }
예제 #5
0
        private bool Initialize(GeometryManager manager, Type vertexType, int size, bool pointsprites, bool dynamic)
        {
            if (IsTypeValid(vertexType))
            {
                try
                {
                    D3d.Pool  d3dPool  = D3d.Pool.Managed;
                    D3d.Usage d3dUsage = D3d.Usage.WriteOnly;

                    if (dynamic)
                    {
                        d3dUsage |= D3d.Usage.Dynamic;
                    }

                    if (pointsprites)
                    {
                        d3dUsage |= D3d.Usage.Points;
                    }

                    d3dManager    = manager;
                    d3dVertexType = vertexType;
                    d3dVertexSize = size;

                    d3dVertexBuffer = new D3d.VertexBuffer(vertexType,
                                                           size,
                                                           manager.Device.D3dDevice,
                                                           d3dUsage,
                                                           D3d.VertexFormats.None,
                                                           d3dPool);

                    return(true);
                }
                catch (D3d.InvalidCallException e)
                {
                    log.Warning("Unable to create vertex stream: {0}", e.Message);
                }
                catch (D3d.OutOfVideoMemoryException e)
                {
                    log.Warning("Unable to create vertex stream: {0}", e.Message);
                }
                catch (OutOfMemoryException e)
                {
                    log.Warning("Unable to create vertex stream: {0}", e.Message);
                }
            }

            return(false);
        }
        //public override Axiom.Core.Texture Create(string name, TextureType type) {
        //    D3DTexture texture = new D3DTexture(name, device, TextureUsage.Default, type);

        //    // Handle 32-bit texture settings
        //    texture.Enable32Bit(is32Bit);

        //    return texture;
        //}

        /// <summary>
        ///    Used to create a blank D3D texture.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="numMipMaps"></param>
        /// <param name="format"></param>
        /// <param name="usage"></param>
        /// <returns></returns>
        //public override Axiom.Core.Texture CreateManual(string name, TextureType type, int width, int height, int numMipMaps, Axiom.Media.PixelFormat format, TextureUsage usage) {
        //    D3DTexture texture = new D3DTexture(name, device, type, width, height, numMipMaps, format, usage);
        //    texture.Enable32Bit(is32Bit);
        //    return texture;
        //}

        // This ends up just discarding the format passed in; the C# methods don't let you supply
        // a "recommended" format.  Ah well.
        public override Axiom.Media.PixelFormat GetNativeFormat(TextureType ttype, Axiom.Media.PixelFormat format, TextureUsage usage)
        {
            // Basic filtering
            D3D.Format d3dPF = D3DHelper.ConvertEnum(D3DHelper.GetClosestSupported(format));

            // Calculate usage
            D3D.Usage d3dusage = 0;
            D3D.Pool  pool     = D3D.Pool.Managed;
            if ((usage & TextureUsage.RenderTarget) != 0)
            {
                d3dusage |= D3D.Usage.RenderTarget;
                pool      = D3D.Pool.Default;
            }
            if ((usage & TextureUsage.Dynamic) != 0)
            {
                d3dusage |= D3D.Usage.Dynamic;
                pool      = D3D.Pool.Default;
            }

            // Use D3DX to adjust pixel format
            switch (ttype)
            {
            case TextureType.OneD:
            case TextureType.TwoD:
                TextureRequirements tReqs;
                TextureLoader.CheckTextureRequirements(device, d3dusage, pool, out tReqs);
                d3dPF = tReqs.Format;
                break;

            case TextureType.ThreeD:
                VolumeTextureRequirements volReqs;
                TextureLoader.CheckVolumeTextureRequirements(device, pool, out volReqs);
                d3dPF = volReqs.Format;
                break;

            case TextureType.CubeMap:
                CubeTextureRequirements cubeReqs;
                TextureLoader.CheckCubeTextureRequirements(device, d3dusage, pool, out cubeReqs);
                d3dPF = cubeReqs.Format;
                break;
            }
            ;
            return(D3DHelper.ConvertEnum(d3dPF));
        }
예제 #7
0
        public static D3D.Usage ConvertEnum(BufferUsage usage)
        {
#if ORIG
            D3D.Usage d3dUsage = 0;

            if (usage == BufferUsage.Dynamic ||
                usage == BufferUsage.DynamicWriteOnly)
            {
                d3dUsage |= D3D.Usage.Dynamic;
            }
            if (usage == BufferUsage.WriteOnly ||
                usage == BufferUsage.StaticWriteOnly ||
                usage == BufferUsage.DynamicWriteOnly)
            {
                d3dUsage |= D3D.Usage.WriteOnly;
            }

            return(d3dUsage);
#else
            D3D.Usage ret = 0;

            if ((usage & BufferUsage.Dynamic) != 0)
            {
#if !NO_OGRE_D3D_MANAGE_BUFFERS
                // Only add the dynamic flag for the default pool, and
                // we use default pool when buffer is discardable
                if ((usage & BufferUsage.Discardable) != 0)
                {
                    ret |= D3D.Usage.Dynamic;
                }
#else
                ret |= D3D.Usage.Dynamic;
#endif
            }
            if ((usage & BufferUsage.WriteOnly) != 0)
            {
                ret |= D3D.Usage.WriteOnly;
            }
            return(ret);
#endif
        }
예제 #8
0
        public D3d.Usage GetUsageFlags(bool dynamic, bool mipmap, bool isTarget)
        {
            D3d.Usage usageFlags = D3d.Usage.WriteOnly;

            if (dynamic)
            {
                usageFlags |= D3d.Usage.Dynamic;
            }

            if (mipmap)
            {
                usageFlags |= D3d.Usage.AutoGenerateMipMap;
            }

            if (isTarget)
            {
                usageFlags |= D3d.Usage.RenderTarget;
            }

            return(usageFlags);
        }
예제 #9
0
        private bool Initialize(GeometryManager manager, int size, bool isLarge, bool dynamic)
        {
            try
            {
                D3d.Pool  d3dPool  = D3d.Pool.Managed;
                D3d.Usage d3dUsage = D3d.Usage.WriteOnly;

                if (dynamic)
                {
                    d3dUsage |= D3d.Usage.Dynamic;
                }

                d3dManager   = manager;
                d3dIndexSize = size;
                d3dIsLarge   = isLarge;

                d3dIndexBuffer = new D3d.IndexBuffer(this.Type, d3dIndexSize, manager.Device.D3dDevice,
                                                     d3dUsage, d3dPool);

                return(true);
            }
            catch (D3d.InvalidCallException e)
            {
                log.Warning("Unable to create index stream: {0}", e.Message);
            }
            catch (D3d.OutOfVideoMemoryException e)
            {
                log.Warning("Unable to create index stream: {0}", e.Message);
            }
            catch (OutOfMemoryException e)
            {
                log.Warning("Unable to create index stream: {0}", e.Message);
            }

            return(false);
        }