public CommonDeviceInterface(int adapter, GraphicsDeviceRequirements baseReq, /*GraphicsDeviceRequirements minReq,*/
                                     string base_path)
        {
            this.adapter = adapter;
            outCaps = GraphicsDeviceCaps.GetAdapterCaps(adapter, baseReq.DeviceType, baseReq.DisplayFormat);
            //minSettings = GraphicsDeviceSettings.CreateFromRequirements(baseReq, outCaps, minReq);
            rzManager = new ResourceManager();
            rzManager.AddSet(new ResourceSet(GlobalResources));

            log = new DirectFileLog(base_path + "general.log");

            rzLoader = new RzLoader();
            rzLoader.RegisterContentLoader(new ImageContentLoader());
        }
        public CommonDeviceInterface(int adapter, GraphicsDeviceRequirements baseReq, /*GraphicsDeviceRequirements minReq,*/
                                     string base_path)
        {
            this.adapter = adapter;
            outCaps      = GraphicsDeviceCaps.GetAdapterCaps(adapter, baseReq.DeviceType, baseReq.DisplayFormat);
            //minSettings = GraphicsDeviceSettings.CreateFromRequirements(baseReq, outCaps, minReq);
            rzManager = new ResourceManager();
            rzManager.AddSet(new ResourceSet(GlobalResources));

            log = new DirectFileLog(base_path + "general.log");

            rzLoader = new RzLoader();
            rzLoader.RegisterContentLoader(new ImageContentLoader());
        }
        public static GraphicsDeviceCaps GetAdapterCaps(int adapter, DeviceType deviceType, Format format)
        {
            GraphicsDeviceCaps caps = new GraphicsDeviceCaps();

            caps.adapter        = adapter;
            caps.adapterDetails = Manager.Adapters.Default.Information;

            caps.caps          = Manager.GetDeviceCaps(adapter, deviceType);
            caps.antialiasCaps = new AntiAliasCaps(adapter, deviceType, format);
            caps.hardwareTnL   = caps.caps.DeviceCaps.SupportsHardwareTransformAndLight;

            caps.vShaderCaps    = caps.caps.VertexShaderCaps;
            caps.vShaderVersion = caps.caps.VertexShaderVersion;
            caps.pShaderCaps    = caps.caps.PixelShaderCaps;
            caps.pShaderVersion = caps.caps.PixelShaderVersion;

            return(caps);
        }
        public static GraphicsDeviceCaps GetAdapterCaps(int adapter, DeviceType deviceType, Format format)
        {
            GraphicsDeviceCaps caps = new GraphicsDeviceCaps();
            caps.adapter = adapter;
            caps.adapterDetails = Manager.Adapters.Default.Information;

            caps.caps = Manager.GetDeviceCaps(adapter, deviceType);
            caps.antialiasCaps = new AntiAliasCaps(adapter, deviceType, format);
            caps.hardwareTnL = caps.caps.DeviceCaps.SupportsHardwareTransformAndLight;

            caps.vShaderCaps = caps.caps.VertexShaderCaps;
            caps.vShaderVersion = caps.caps.VertexShaderVersion;
            caps.pShaderCaps = caps.caps.PixelShaderCaps;
            caps.pShaderVersion = caps.caps.PixelShaderVersion;

            return caps;
        }
        public static GraphicsDeviceSettings CreateFromRequirements(GraphicsDeviceRequirements requirements,
                                                                    GraphicsDeviceCaps caps,
                                                                    GraphicsDeviceRequirements fallbacks,
                                                                    out bool fullyMatchReq)
        {
            if (caps == null)
            {
                caps = GraphicsDeviceCaps.GetDefaultAdapterCaps(requirements);
            }

            GraphicsDeviceSettings settings = new GraphicsDeviceSettings();

            settings.adapter = caps.Adapter;

            Type type = typeof(GraphicsDeviceSettings);

            GraphicsDeviceCaps.OutputCapsCompatibility reqComp      = caps.CheckCompatibility(requirements);
            GraphicsDeviceCaps.OutputCapsCompatibility fallbackComp = caps.CheckCompatibility(fallbacks);

            fullyMatchReq = reqComp.FullMatch;

            // check reqs against caps
            if (reqComp.SupportDeviceType)
            {
                settings.devType = requirements.DeviceType;
            }
            else if (fallbackComp.SupportDeviceType)
            {
                settings.devType = fallbacks.DeviceType;
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("DeviceType"),
                                                  requirements.DeviceType, null);
            }

            if (reqComp.SupportDeviceFormat)
            {
                settings.devFormat = requirements.DisplayFormat;
            }
            else if (fallbackComp.SupportDeviceFormat)
            {
                settings.devFormat = fallbacks.DisplayFormat;
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("DeviceFormat"),
                                                  requirements.DisplayFormat, null);
            }

            if (reqComp.SupportDepthFormat)
            {
                settings.depthFormat = requirements.DepthFormats[0];
            }
            else if (fallbackComp.SupportDepthFormat)
            {
                settings.depthFormat = fallbacks.DepthFormats[0];
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("DepthFormat"),
                                                  requirements.DepthFormats[0], null);
            }

            if (caps.HardwareTnL && requirements.HardwareTnL)
            {
                settings.createFlags = CreateFlags.HardwareVertexProcessing;
            }
            else if (!requirements.HardwareTnL)
            {
                settings.createFlags = CreateFlags.SoftwareVertexProcessing;
            }
            else if (!fallbacks.HardwareTnL)
            {
                settings.createFlags = CreateFlags.SoftwareVertexProcessing;
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("CreateFlags"),
                                                  requirements.HardwareTnL, null);
            }

            if (requirements.MultiSample <= caps.AntiAliasing.MaxSupported)
            {
                settings.multisample = requirements.MultiSample;
            }
            else if (fallbacks.MultiSample <= caps.AntiAliasing.MaxSupported)
            {
                settings.multisample = fallbacks.MultiSample;
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("AntiAliasing"),
                                                  requirements.MultiSample, caps.AntiAliasing.MaxSupported);
            }

            return(settings);
        }
        public static GraphicsDeviceSettings CreateFromRequirements(GraphicsDeviceRequirements requirements,
                                                                    GraphicsDeviceCaps caps,
                                                                    GraphicsDeviceRequirements fallbacks,
                                                                    out bool fullyMatchReq)
        {
            if (caps == null)
                caps = GraphicsDeviceCaps.GetDefaultAdapterCaps(requirements);

            GraphicsDeviceSettings settings = new GraphicsDeviceSettings();
            settings.adapter = caps.Adapter;

            Type type = typeof(GraphicsDeviceSettings);

            GraphicsDeviceCaps.OutputCapsCompatibility reqComp = caps.CheckCompatibility(requirements);
            GraphicsDeviceCaps.OutputCapsCompatibility fallbackComp = caps.CheckCompatibility(fallbacks);

            fullyMatchReq = reqComp.FullMatch;

            // check reqs against caps
            if (reqComp.SupportDeviceType)
                settings.devType = requirements.DeviceType;
            else if (fallbackComp.SupportDeviceType)
                settings.devType = fallbacks.DeviceType;
            else
                throw new OutputSettingsException(type.GetProperty("DeviceType"),
                                                  requirements.DeviceType, null);

            if (reqComp.SupportDeviceFormat)
                settings.devFormat = requirements.DisplayFormat;
            else if (fallbackComp.SupportDeviceFormat)
                settings.devFormat = fallbacks.DisplayFormat;
            else
                throw new OutputSettingsException(type.GetProperty("DeviceFormat"),
                                                  requirements.DisplayFormat, null);

            if (reqComp.SupportDepthFormat)
                settings.depthFormat = requirements.DepthFormats[0];
            else if (fallbackComp.SupportDepthFormat)
                settings.depthFormat = fallbacks.DepthFormats[0];
            else
                throw new OutputSettingsException(type.GetProperty("DepthFormat"),
                                                  requirements.DepthFormats[0], null);

            if (caps.HardwareTnL && requirements.HardwareTnL)
                settings.createFlags = CreateFlags.HardwareVertexProcessing;
            else if (!requirements.HardwareTnL)
                settings.createFlags = CreateFlags.SoftwareVertexProcessing;
            else if (!fallbacks.HardwareTnL)
                settings.createFlags = CreateFlags.SoftwareVertexProcessing;
            else
                throw new OutputSettingsException(type.GetProperty("CreateFlags"),
                                                  requirements.HardwareTnL, null);

            if (requirements.MultiSample <= caps.AntiAliasing.MaxSupported)
                settings.multisample = requirements.MultiSample;
            else if (fallbacks.MultiSample <= caps.AntiAliasing.MaxSupported)
                settings.multisample = fallbacks.MultiSample;
            else
                throw new OutputSettingsException(type.GetProperty("AntiAliasing"),
                                                  requirements.MultiSample, caps.AntiAliasing.MaxSupported);

            return settings;
        }
        public RenderingContext3D(Control targetRenderArea, GraphicsProfile profile, CommonDeviceInterface cdi,
                                  HashTableSettings localSettings)
        {
            isDeviceLost = false;
            isActive = false;
            hasFocus = false;

            this.targetRenderArea = targetRenderArea;
            outProfile = profile;
            log = cdi.GeneralLog;

            presentParams = new PresentParameters();
            outCaps = cdi.DeviceCaps;

            layers = new LayerStack();

            InitializeEnvironment(cdi, localSettings);

            view3D = new RenderingView3DPer(Matrix.Identity, Matrix.Identity);
            view3D.Near = 0.1f;
            view3D.Far = 25;

            int sceneSize = 60;
            sManager = new GenericSceneManager<SceneEntity>(gDevice, outSettings,
                                                            new Vector3(sceneSize / 2f, sceneSize / 2f, sceneSize / 2f), sceneSize);
        }
        protected virtual void InitializeEnvironment(CommonDeviceInterface cdi, HashTableSettings localSettings)
        {
            // Get device settings
            if (outCaps == null)
                outCaps = GraphicsDeviceCaps.GetDefaultAdapterCaps(outProfile.RecommendedVariations[0]);
            // find first recommended settings with full match
            bool fullMatch = false;
            outSettings = GraphicsDeviceSettings.CreateFromRequirements(outProfile.RecommendedVariation,
                                                                        outCaps, outProfile.MinReqs,
                                                                        out fullMatch);

            // Set up the presentation parameters
            presentParams.Windowed = outProfile.RecommendedVariations[0].Windowed;
            presentParams.SwapEffect = SwapEffect.Discard;
            presentParams.AutoDepthStencilFormat = outSettings.DepthFormat;
            presentParams.EnableAutoDepthStencil = (outSettings.DepthFormat != DepthFormat.Unknown);
            presentParams.MultiSample = outSettings.MultiSample;

            CreateDevice();

            devIf = new DeviceInterface(gDevice, cdi, localSettings);

            gPipeline = new GraphicsPipeline(gDevice);
        }