public override void Create(string name, int width, int height, bool fullScreen, NamedParameterList miscParams) { SWF.Control parentHWnd = null; SWF.Control externalHWnd = null; this._fsaaType = D3D9.MultisampleType.None; this._fsaaQuality = 0; fsaa = 0; this._vSync = false; this._vSyncInterval = 1; var title = name; var colorDepth = 32; var left = int.MaxValue; // Defaults to screen center var top = int.MaxValue; // Defaults to screen center var depthBuffer = true; var border = ""; var outerSize = false; var enableDoubleClick = false; this._useNVPerfHUD = false; //var fsaaSamples = 0; //Not used, even in Ogre var fsaaHint = string.Empty; var monitorIndex = -1; if (miscParams != null) { object opt; // left (x) if (miscParams.TryGetValue("left", out opt)) { left = Int32.Parse(opt.ToString()); } // top (y) if (miscParams.TryGetValue("top", out opt)) { top = Int32.Parse(opt.ToString()); } // Window title if (miscParams.TryGetValue("title", out opt)) { title = (string)opt; } // parentWindowHandle -> parentHWnd if (miscParams.TryGetValue("parentWindowHandle", out opt)) { // This is Axiom specific var handle = opt; var ptr = IntPtr.Zero; if (handle.GetType() == typeof(IntPtr)) { ptr = (IntPtr)handle; } else if (handle.GetType() == typeof(Int32)) { ptr = new IntPtr((int)handle); } else { throw new AxiomException("unhandled parentWindowHandle type"); } parentHWnd = SWF.Control.FromHandle(ptr); } // externalWindowHandle -> externalHWnd if (miscParams.TryGetValue("externalWindowHandle", out opt)) { // This is Axiom specific var handle = opt; var ptr = IntPtr.Zero; if (handle.GetType() == typeof(IntPtr)) { ptr = (IntPtr)handle; } else if (handle.GetType() == typeof(Int32)) { ptr = new IntPtr((int)handle); } else { throw new AxiomException("unhandled externalWindowHandle type"); } externalHWnd = SWF.Control.FromHandle(ptr); } // vsync [parseBool] if (miscParams.TryGetValue("vsync", out opt)) { this._vSync = bool.Parse(opt.ToString()); } // vsyncInterval [parseUnsignedInt] if (miscParams.TryGetValue("vsyncInterval", out opt)) { this._vSyncInterval = Int32.Parse(opt.ToString()); } // displayFrequency if (miscParams.TryGetValue("displayFrequency", out opt)) { this._displayFrequency = Int32.Parse(opt.ToString()); } // colorDepth if (miscParams.TryGetValue("colorDepth", out opt)) { colorDepth = Int32.Parse(opt.ToString()); } // depthBuffer [parseBool] if (miscParams.TryGetValue("depthBuffer", out opt)) { depthBuffer = bool.Parse(opt.ToString()); } //FSAA settings // FSAA type if (miscParams.TryGetValue("FSAA", out opt)) { this._fsaaType = (D3D9.MultisampleType)opt; } if (miscParams.TryGetValue("FSAAHint", out opt)) { fsaaHint = (string)opt; } // window border style if (miscParams.TryGetValue("border", out opt)) { border = ((string)opt).ToLower(); } // set outer dimensions? if (miscParams.TryGetValue("outerDimensions", out opt)) { outerSize = bool.Parse(opt.ToString()); } // NV perf HUD? if (miscParams.TryGetValue("useNVPerfHUD", out opt)) { this._useNVPerfHUD = bool.Parse(opt.ToString()); } // sRGB? if (miscParams.TryGetValue("gamma", out opt)) { hwGamma = bool.Parse(opt.ToString()); } // monitor index if (miscParams.TryGetValue("monitorIndex", out opt)) { monitorIndex = Int32.Parse(opt.ToString()); } // enable double click messages if (miscParams.TryGetValue("enableDoubleClick", out opt)) { enableDoubleClick = bool.Parse(opt.ToString()); } } // Destroy current window if any if (this._windowHandle != null) { Destroy(); } if (externalHWnd == null) { var dwStyle = WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPCHILDREN; var dwStyleEx = (WindowsExtendedStyle)0; var monitorHandle = IntPtr.Zero; RECT rc; // If we specified which adapter we want to use - find it's monitor. if (monitorIndex != -1) { var direct3D9 = D3D9RenderSystem.Direct3D9; for (var i = 0; i < direct3D9.AdapterCount; ++i) { if (i != monitorIndex) { continue; } monitorHandle = direct3D9.GetAdapterMonitor(i); break; } } // If we didn't specified the adapter index, or if it didn't find it if (monitorHandle == IntPtr.Zero) { // Fill in anchor point. var windowAnchorPoint = new Point(left, top); // Get the nearest monitor to this window. monitorHandle = ScreenHelper.GetHandle(windowAnchorPoint); } // Get the target monitor info var monitorInfo = ScreenHelper.FromHandle(monitorHandle); var winWidth = width; var winHeight = height; // No specified top left -> Center the window in the middle of the monitor if (left == int.MaxValue || top == int.MaxValue) { var screenw = monitorInfo.WorkingArea.Right - monitorInfo.WorkingArea.Left; var screenh = monitorInfo.WorkingArea.Bottom - monitorInfo.WorkingArea.Top; // clamp window dimensions to screen size var outerw = (winWidth < screenw) ? winWidth : screenw; var outerh = (winHeight < screenh) ? winHeight : screenh; if (left == int.MaxValue) { left = monitorInfo.WorkingArea.Left + (screenw - outerw) / 2; } else if (monitorIndex != -1) { left += monitorInfo.WorkingArea.Left; } if (top == int.MaxValue) { top = monitorInfo.WorkingArea.Top + (screenh - outerh) / 2; } else if (monitorIndex != -1) { top += monitorInfo.WorkingArea.Top; } } else if (monitorIndex != -1) { left += monitorInfo.WorkingArea.Left; top += monitorInfo.WorkingArea.Top; } this.width = this._desiredWidth = width; this.height = this._desiredHeight = height; this.top = top; this.left = left; if (fullScreen) { dwStyleEx |= WindowsExtendedStyle.WS_EX_TOPMOST; dwStyle |= WindowStyles.WS_POPUP; this.top = monitorInfo.Bounds.Top; this.left = monitorInfo.Bounds.Left; } else { if (parentHWnd != null) { dwStyle |= WindowStyles.WS_CHILD; } else { if (border == "none") { dwStyle |= WindowStyles.WS_POPUP; } else if (border == "fixed") { dwStyle |= WindowStyles.WS_OVERLAPPED | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_MINIMIZEBOX; } else { dwStyle |= WindowStyles.WS_OVERLAPPEDWINDOW; } } AdjustWindow(width, height, dwStyle, out winWidth, out winHeight); if (!outerSize) { // Calculate window dimensions required // to get the requested client area rc = new RECT(0, 0, this.width, this.height); AdjustWindowRect(ref rc, dwStyle, false); this.width = rc.Right - rc.Left; this.height = rc.Bottom - rc.Top; // Clamp window rect to the nearest display monitor. if (this.left < monitorInfo.WorkingArea.Left) { this.left = monitorInfo.WorkingArea.Left; } if (this.top < monitorInfo.WorkingArea.Top) { this.top = monitorInfo.WorkingArea.Top; } if (winWidth > monitorInfo.WorkingArea.Right - this.left) { winWidth = monitorInfo.WorkingArea.Right - this.left; } if (winHeight > monitorInfo.WorkingArea.Bottom - this.top) { winHeight = monitorInfo.WorkingArea.Bottom - this.top; } } } WindowClassStyle classStyle = 0; if (enableDoubleClick) { classStyle |= WindowClassStyle.CS_DBLCLKS; } // Create our main window this._isExternal = false; var wnd = new DefaultForm(classStyle, dwStyleEx, title, dwStyle, this.left, this.top, winWidth, winHeight, parentHWnd); wnd.RenderWindow = this; this._windowHandle = wnd; this._style = dwStyle; WindowEventMonitor.Instance.RegisterWindow(this); } else { this._windowHandle = externalHWnd; this._isExternal = true; } // top and left represent outer window coordinates var rc2 = new System.Drawing.Rectangle(this._windowHandle.Location, this._windowHandle.Size); this.top = rc2.Top; this.left = rc2.Left; // width and height represent interior drawable area rc2 = this._windowHandle.ClientRectangle; this.width = rc2.Right; this.height = rc2.Bottom; this.name = name; isDepthBuffered = depthBuffer; isFullScreen = fullScreen; this.colorDepth = colorDepth; LogManager.Instance.Write("D3D9 : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp", this.name, this.width, this.height, ColorDepth); active = true; this._isClosed = false; }
private void _createCubeTexture( D3D9.Device d3d9Device ) { // we must have those defined here Debug.Assert( SrcWidth > 0 || SrcHeight > 0 ); // determine wich D3D9 pixel format we'll use var d3dPF = _chooseD3DFormat( d3d9Device ); // let's D3DX check the corrected pixel format var texRequires = D3D9.CubeTexture.CheckRequirements( d3d9Device, 0, 0, 0, d3dPF, this._d3dPool ); d3dPF = texRequires.Format; // Use D3DX to help us create the texture, this way it can adjust any relevant sizes var d3dUsage = ( usage & TextureUsage.RenderTarget ) != 0 ? D3D9.Usage.RenderTarget : 0; var numMips = requestedMipmapCount == (int)TextureMipmap.Unlimited ? -1 : requestedMipmapCount + 1; // Check dynamic textures if ( ( usage & TextureUsage.Dynamic ) != 0 ) { if ( _canUseDynamicTextures( d3d9Device, d3dUsage, D3D9.ResourceType.CubeTexture, d3dPF ) ) { d3dUsage |= D3D9.Usage.Dynamic; this._dynamicTextures = true; } else { this._dynamicTextures = false; } } // Check sRGB support if ( hwGamma ) { this._hwGammaReadSupported = _canUseHardwareGammaCorrection( d3d9Device, d3dUsage, D3D9.ResourceType.CubeTexture, d3dPF, false ); if ( ( usage & TextureUsage.RenderTarget ) != 0 ) { this._hwGammaWriteSupported = _canUseHardwareGammaCorrection( d3d9Device, d3dUsage, D3D9.ResourceType.CubeTexture, d3dPF, true ); } } // Check FSAA level if ( ( usage & TextureUsage.RenderTarget ) != 0 ) { var rsys = (D3D9RenderSystem)Root.Instance.RenderSystem; rsys.DetermineFSAASettings( d3d9Device, fsaa, fsaaHint, d3dPF, false, out this._fsaaType, out this._fsaaQuality ); } else { this._fsaaType = D3D9.MultisampleType.None; this._fsaaQuality = 0; } var device = D3D9RenderSystem.DeviceManager.GetDeviceFromD3D9Device( d3d9Device ); var rkCurCaps = device.D3D9DeviceCaps; // check if mip map cube textures are supported mipmapsHardwareGenerated = false; if ( ( rkCurCaps.TextureCaps & D3D9.TextureCaps.MipCubeMap ) != 0 ) { if ( ( usage & TextureUsage.AutoMipMap ) != 0 && requestedMipmapCount != 0 ) { // use auto.gen. if available; mipmapsHardwareGenerated = _canAutoGenMipMaps( d3d9Device, d3dUsage, D3D9.ResourceType.CubeTexture, d3dPF ); if ( mipmapsHardwareGenerated ) { d3dUsage |= D3D9.Usage.AutoGenerateMipMap; numMips = 0; } } } else { // no mip map support for this kind of texture :( MipmapCount = 0; numMips = 1; } // derive the pool to use _determinePool(); // Get or create new texture resources structure. var textureResources = _getTextureResources( d3d9Device ); if ( textureResources != null ) { _freeTextureResources( d3d9Device, textureResources ); } else { textureResources = _allocateTextureResources( d3d9Device ); } // create the cube texture textureResources.CubeTexture = new D3D9.CubeTexture( d3d9Device, SrcWidth, numMips, d3dUsage, d3dPF, this._d3dPool ); // set the base texture we'll use in the render system textureResources.BaseTexture = textureResources.CubeTexture.QueryInterface<D3D9.BaseTexture>(); // set final tex. attributes from tex. description // they may differ from the source image !!! var desc = textureResources.CubeTexture.GetLevelDescription( 0 ); if ( this._fsaaType != 0 ) { // create AA surface textureResources.FSAASurface = D3D9.Surface.CreateRenderTarget( d3d9Device, desc.Width, desc.Height, d3dPF, this._fsaaType, this._fsaaQuality, false ); } _setFinalAttributes( d3d9Device, textureResources, desc.Width, desc.Height, 1, D3D9Helper.ConvertEnum( desc.Format ) ); // Set best filter type if ( mipmapsHardwareGenerated ) { textureResources.BaseTexture.AutoMipGenerationFilter = _getBestFilterMethod( d3d9Device ); } }
public override void Create( string name, int width, int height, bool fullScreen, NamedParameterList miscParams ) { SWF.Control parentHWnd = null; SWF.Control externalHWnd = null; this._fsaaType = D3D9.MultisampleType.None; this._fsaaQuality = 0; fsaa = 0; this._vSync = false; this._vSyncInterval = 1; var title = name; var colorDepth = 32; var left = int.MaxValue; // Defaults to screen center var top = int.MaxValue; // Defaults to screen center var depthBuffer = true; var border = ""; var outerSize = false; var enableDoubleClick = false; this._useNVPerfHUD = false; //var fsaaSamples = 0; //Not used, even in Ogre var fsaaHint = string.Empty; var monitorIndex = -1; if ( miscParams != null ) { object opt; // left (x) if ( miscParams.TryGetValue( "left", out opt ) ) { left = Int32.Parse( opt.ToString() ); } // top (y) if ( miscParams.TryGetValue( "top", out opt ) ) { top = Int32.Parse( opt.ToString() ); } // Window title if ( miscParams.TryGetValue( "title", out opt ) ) { title = (string)opt; } // parentWindowHandle -> parentHWnd if ( miscParams.TryGetValue( "parentWindowHandle", out opt ) ) { parentHWnd = GetControlFromParameter( opt ); } // externalWindowHandle -> externalHWnd if ( miscParams.TryGetValue( "externalWindowHandle", out opt ) ) { externalHWnd = GetControlFromParameter(opt); } // vsync [parseBool] if ( miscParams.TryGetValue( "vsync", out opt ) ) { this._vSync = bool.Parse( opt.ToString() ); } // vsyncInterval [parseUnsignedInt] if ( miscParams.TryGetValue( "vsyncInterval", out opt ) ) { this._vSyncInterval = Int32.Parse( opt.ToString() ); } // displayFrequency if ( miscParams.TryGetValue( "displayFrequency", out opt ) ) { this._displayFrequency = Int32.Parse( opt.ToString() ); } // colorDepth if ( miscParams.TryGetValue( "colorDepth", out opt ) ) { colorDepth = Int32.Parse( opt.ToString() ); } // depthBuffer [parseBool] if ( miscParams.TryGetValue( "depthBuffer", out opt ) ) { depthBuffer = bool.Parse( opt.ToString() ); } //FSAA settings // FSAA type if ( miscParams.TryGetValue( "FSAA", out opt ) ) { this._fsaaType = (D3D9.MultisampleType)opt; } if ( miscParams.TryGetValue( "FSAAHint", out opt ) ) { fsaaHint = (string)opt; } // window border style if ( miscParams.TryGetValue( "border", out opt ) ) { border = ( (string)opt ).ToLower(); } // set outer dimensions? if ( miscParams.TryGetValue( "outerDimensions", out opt ) ) { outerSize = bool.Parse( opt.ToString() ); } // NV perf HUD? if ( miscParams.TryGetValue( "useNVPerfHUD", out opt ) ) { this._useNVPerfHUD = bool.Parse( opt.ToString() ); } // sRGB? if ( miscParams.TryGetValue( "gamma", out opt ) ) { hwGamma = bool.Parse( opt.ToString() ); } // monitor index if ( miscParams.TryGetValue( "monitorIndex", out opt ) ) { monitorIndex = Int32.Parse( opt.ToString() ); } // enable double click messages if ( miscParams.TryGetValue( "enableDoubleClick", out opt ) ) { enableDoubleClick = bool.Parse( opt.ToString() ); } } // Destroy current window if any if ( this._windowHandle != null ) { Destroy(); } if ( externalHWnd == null ) { var dwStyle = WindowStyles.Visible | WindowStyles.ClipChildren; var dwStyleEx = (WindowsExtendedStyle)0; var monitorHandle = IntPtr.Zero; // If we specified which adapter we want to use - find it's monitor. if ( monitorIndex != -1 ) { var direct3D9 = D3D9RenderSystem.Direct3D9; for ( var i = 0; i < direct3D9.AdapterCount; ++i ) { if ( i != monitorIndex ) { continue; } monitorHandle = direct3D9.GetAdapterMonitor( i ); break; } } // If we didn't specified the adapter index, or if it didn't find it if ( monitorHandle == IntPtr.Zero ) { // Fill in anchor point. var windowAnchorPoint = new Point( left, top ); // Get the nearest monitor to this window. monitorHandle = ScreenHelper.GetHandle( windowAnchorPoint ); } // Get the target monitor info var monitorInfo = ScreenHelper.FromHandle( monitorHandle ); var winWidth = width; var winHeight = height; // No specified top left -> Center the window in the middle of the monitor if ( left == int.MaxValue || top == int.MaxValue ) { var screenw = monitorInfo.WorkingArea.Right - monitorInfo.WorkingArea.Left; var screenh = monitorInfo.WorkingArea.Bottom - monitorInfo.WorkingArea.Top; // clamp window dimensions to screen size var outerw = ( winWidth < screenw ) ? winWidth : screenw; var outerh = ( winHeight < screenh ) ? winHeight : screenh; if ( left == int.MaxValue ) { left = monitorInfo.WorkingArea.Left + ( screenw - outerw )/2; } else if ( monitorIndex != -1 ) { left += monitorInfo.WorkingArea.Left; } if ( top == int.MaxValue ) { top = monitorInfo.WorkingArea.Top + ( screenh - outerh )/2; } else if ( monitorIndex != -1 ) { top += monitorInfo.WorkingArea.Top; } } else if ( monitorIndex != -1 ) { left += monitorInfo.WorkingArea.Left; top += monitorInfo.WorkingArea.Top; } this.width = this._desiredWidth = width; this.height = this._desiredHeight = height; this.top = top; this.left = left; if ( fullScreen ) { dwStyleEx |= WindowsExtendedStyle.TopMost; dwStyle |= WindowStyles.Popup; this.top = monitorInfo.Bounds.Top; this.left = monitorInfo.Bounds.Left; } else { if ( parentHWnd != null ) { dwStyle |= WindowStyles.Child; } else { if ( border == "none" ) { dwStyle |= WindowStyles.Popup; } else if ( border == "fixed" ) { dwStyle |= WindowStyles.Overlapped | WindowStyles.Border | WindowStyles.Caption | WindowStyles.SystemMenu | WindowStyles.MinimizeBox; } else { dwStyle |= WindowStyles.OverlappedWindow; } } AdjustWindow( width, height, dwStyle, out winWidth, out winHeight ); if ( !outerSize ) { // Calculate window dimensions required // to get the requested client area var rc = new RECT( 0, 0, this.width, this.height ); AdjustWindowRect( ref rc, dwStyle, false ); this.width = rc.Right - rc.Left; this.height = rc.Bottom - rc.Top; // Clamp window rect to the nearest display monitor. if ( this.left < monitorInfo.WorkingArea.Left ) { this.left = monitorInfo.WorkingArea.Left; } if ( this.top < monitorInfo.WorkingArea.Top ) { this.top = monitorInfo.WorkingArea.Top; } if ( winWidth > monitorInfo.WorkingArea.Right - this.left ) { winWidth = monitorInfo.WorkingArea.Right - this.left; } if ( winHeight > monitorInfo.WorkingArea.Bottom - this.top ) { winHeight = monitorInfo.WorkingArea.Bottom - this.top; } } } WindowClassStyle classStyle = 0; if ( enableDoubleClick ) { classStyle |= WindowClassStyle.DoubleClicks; } // Create our main window this._isExternal = false; this._windowHandle = new DefaultForm( classStyle, dwStyleEx, title, dwStyle, this.left, this.top, winWidth, winHeight, parentHWnd ) { RenderWindow = this }; this._style = dwStyle; WindowEventMonitor.Instance.RegisterWindow( this ); } else { this._windowHandle = externalHWnd; this._isExternal = true; } // top and left represent outer window coordinates var rc2 = new System.Drawing.Rectangle( this._windowHandle.Location, this._windowHandle.Size ); this.top = rc2.Top; this.left = rc2.Left; // width and height represent interior drawable area rc2 = this._windowHandle.ClientRectangle; this.width = rc2.Right; this.height = rc2.Bottom; this.name = name; isDepthBuffered = depthBuffer; isFullScreen = fullScreen; this.colorDepth = colorDepth; LogManager.Instance.Write( "D3D9 : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp", this.name, this.width, this.height, ColorDepth ); active = true; this._isClosed = false; }