Example #1
0
        /// <summary>
        /// Initializes the <see cref="GorgonGraphics"/> class.
        /// </summary>
        /// <param name="device">Video device to use.</param>
        /// <param name="featureLevel">The maximum feature level to support for the devices enumerated.</param>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="featureLevel"/> parameter is invalid.</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when Gorgon could not find any video devices that are Shader Model 5, or the down level interfaces (Shader Model 4, and lesser).
        /// <para>-or-</para>
        /// <para>Thrown if the operating system version is not supported.  Gorgon Graphics requires at least Windows Vista Service Pack 2 or higher.</para>
        /// </exception>
        /// <remarks>
        /// The <paramref name="device"/> parameter is the video device that should be used with Gorgon.  If the user passes NULL (Nothing in VB.Net), then the primary device will be used.
        /// To determine the devices on the system, check the <see cref="GorgonLibrary.Graphics.GorgonVideoDeviceEnumerator">GorgonVideoDeviceEnumerator</see> class.  The primary device will be the first device in this collection.
        /// <para>The user may pass in a feature level to the featureLevel parameter to limit the feature levels available.  Note that the feature levels imply all feature levels up until the feature level passed in, for example, passing <c>DeviceFeatureLevel.SM4</c> will only allow functionality
        /// for both Shader Model 4, and Shader Model 2/3 capable video devices, while DeviceFeatureLevel.SM4_1 will include Shader Model 4 with a 4.1 profile and Shader model 2/3 video devices.</para>
        /// <para>If a feature level is not supported by the hardware, then Gorgon will not use that feature level.  That is, passing a SM5 feature level with a SM4 card will only use a SM4 feature level.  If the user omits the feature level (in one of the constructor
        /// overloads), then Gorgon will use the best available feature level for the video device being used.</para>
        /// </remarks>
        public GorgonGraphics(GorgonVideoDevice device, DeviceFeatureLevel featureLevel)
        {
            ResetFullscreenOnFocus = true;
            ImmediateContext       = this;

            if (featureLevel == DeviceFeatureLevel.Unsupported)
            {
                throw new ArgumentException(Resources.GORGFX_FEATURE_LEVEL_UNKNOWN);
            }

            if (GorgonComputerInfo.OperatingSystemVersion.Major < 6)
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_INVALID_OS);
            }

            Gorgon.Log.Print("Gorgon Graphics initializing...", LoggingLevel.Simple);

            // Track our objects.
            _trackedObjects = new GorgonDisposableObjectCollection();

#if DEBUG
            if (!SharpDX.Configuration.EnableObjectTracking)
            {
                SharpDX.Configuration.EnableObjectTracking = true;
            }
#else
            SharpDX.Configuration.EnableObjectTracking = false;
#endif

            if (device == null)
            {
                if (GorgonVideoDeviceEnumerator.VideoDevices.Count == 0)
                {
                    GorgonVideoDeviceEnumerator.Enumerate(false, false);
                }

                // Use the first device in the list.
                device = GorgonVideoDeviceEnumerator.VideoDevices[0];
            }

            VideoDevice = device;

            var D3DDeviceData = VideoDevice.GetDevice(VideoDevice.VideoDeviceType, featureLevel);

            // Create the DXGI factory for the video device.
            GIFactory = D3DDeviceData.Item1;
            Adapter   = D3DDeviceData.Item2;
            D3DDevice = D3DDeviceData.Item3;

            Context = D3DDevice.ImmediateContext;
            Context.ClearState();
            VideoDevice.Graphics = ImmediateContext;

            CreateStates();

            Gorgon.AddTrackedObject(this);

            Gorgon.Log.Print("Gorgon Graphics initialized.", LoggingLevel.Simple);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonGraphics"/> class.
        /// </summary>
        /// <param name="graphics">The immediate graphics context.</param>
        internal GorgonGraphics(GorgonGraphics graphics)
        {
            // Inherit the object tracker from the immediate context.
            _trackedObjects = graphics._trackedObjects;

            Context = new D3D.DeviceContext(graphics.D3DDevice);
            Context.ClearState();
            ImmediateContext = graphics;

            VideoDevice = graphics.VideoDevice;
            GIFactory   = graphics.GIFactory;
            Adapter     = graphics.Adapter;
            D3DDevice   = graphics.D3DDevice;

            CreateStates();

            graphics.AddTrackedObject(this);
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gorgon2D"/> class.
        /// </summary>
        /// <param name="target">The primary render target to use.</param>
        /// <param name="vertexCacheSize">The number of vertices that can be placed in vertex cache.</param>
        /// <param name="autoCreatedTarget">TRUE if Gorgon created the target, FALSE if the user created the target.</param>
        internal Gorgon2D(GorgonRenderTargetView target, int vertexCacheSize, bool autoCreatedTarget)
        {
            _systemCreatedTarget = autoCreatedTarget;

            _cache = new Gorgon2DVertexCache(this, vertexCacheSize.Max(1024));

            IsBlendingEnabled  = true;
            IsAlphaTestEnabled = true;

            TrackedObjects = new GorgonDisposableObjectCollection();
            Graphics       = target.Resource.Graphics;
            DefaultTarget  = target;

            _logoSprite = new GorgonSprite(this, "Gorgon2D.LogoSprite")
            {
                Anchor        = new Vector2(Graphics.Textures.GorgonLogo.Settings.Size),
                Texture       = Graphics.Textures.GorgonLogo,
                TextureRegion = new RectangleF(Vector2.Zero, new Vector2(1)),
                Color         = Color.White,
                Size          = Graphics.Textures.GorgonLogo.Settings.Size
            };
            DefaultCamera = new Gorgon2DOrthoCamera(this,
                                                    "Gorgon.Camera.Default",
                                                    new RectangleF(0, 0, _defaultTarget.Width, _defaultTarget.Height),
                                                    0,
                                                    1.0f)
            {
                AutoUpdate = true
            };

            Renderables = new GorgonRenderables(this, _cache);
            Drawing     = new GorgonDrawing(this);

            // Perform further initialization.
            Initialize();
        }