- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/Backup/DXCommon/dxmutdata.cs

Go to the documentation of this file.

    00001 //--------------------------------------------------------------------------------------
    00002 // File: DXMUTData.cs
    00003 //
    00004 // DirectX SDK Managed Direct3D sample framework data class
    00005 //
    00006 // Copyright (c) Microsoft Corporation. All rights reserved.
    00007 //--------------------------------------------------------------------------------------
    00008 using System;
    00009 using System.Windows.Forms;
    00010 using System.Collections;
    00011 using Microsoft.DirectX;
    00012 using Microsoft.DirectX.Direct3D;
    00013
    00014 namespace Microsoft.Samples.DirectX.UtilityToolkit
    00015 {
    00016
    00017     #region Framework Interfaces and Eventargs classes
    00019     public interface IFrameworkCallback
    00020     {
    00021         void OnFrameMove(Device device, double totalTime, float elapsedTime);
    00022         void OnFrameRender(Device device, double totalTime, float elapsedTime);
    00023     }
    00024
    00026     public interface IDeviceCreation
    00027     {
    00028         bool IsDeviceAcceptable(Caps caps, Format adapterFormat, Format backBufferFormat, bool isWindowed);
    00029         void ModifyDeviceSettings(DeviceSettings settings, Caps caps);
    00030     }
    00031
    00033     public class DeviceEventArgs : EventArgs
    00034     {
    00035         // Class data
    00036         public Device Device;
    00037         public SurfaceDescription BackBufferDescription;
    00038
    00039         public DeviceEventArgs(Device d, SurfaceDescription desc)
    00040         {
    00041             Device = d;
    00042             BackBufferDescription = desc;
    00043         }
    00044     }
    00046     public delegate void DeviceEventHandler(object sender, DeviceEventArgs e);
    00047     #endregion
    00048
    00049     #region Device Settings
    00053     public class DeviceSettings : ICloneable
    00054     {
    00055         public uint AdapterOrdinal;
    00056         public DeviceType DeviceType;
    00057         public Format AdapterFormat;
    00058         public CreateFlags BehaviorFlags;
    00059         public PresentParameters presentParams;
    00060
    00061         #region ICloneable Members
    00063         public DeviceSettings Clone()
    00064         {
    00065             DeviceSettings clonedObject = new DeviceSettings();
    00066             clonedObject.presentParams = (PresentParameters)this.presentParams.Clone();
    00067             clonedObject.AdapterFormat = this.AdapterFormat;
    00068             clonedObject.AdapterOrdinal = this.AdapterOrdinal;
    00069             clonedObject.BehaviorFlags = this.BehaviorFlags;
    00070             clonedObject.DeviceType = this.DeviceType;
    00071
    00072             return clonedObject;
    00073         }
    00075         object ICloneable.Clone() { throw new NotSupportedException("Use the strongly typed overload instead."); }
    00076         #endregion
    00077     }
    00078     #endregion
    00079
    00080     #region User Timers
    00082     public struct TimerData
    00083     {
    00084         public TimerCallback callback;
    00085         public float TimeoutInSecs;
    00086         public float Countdown;
    00087         public bool IsEnabled;
    00088     }
    00089     #endregion
    00090
    00091     #region Callback methods
    00092     public delegate IntPtr WndProcCallback(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool NoFurtherProcessing);
    00093     public delegate void TimerCallback(uint eventId);
    00094     #endregion
    00095
    00096     #region Matching Options
    00100     public enum MatchType
    00101     {
    00102         IgnoreInput, // Use the closest valid value to a default
    00103         PreserveInput, // Use input without change, but may cause no valid device to be found
    00104         ClosestToInput // Use the closest valid value to the input
    00105     }
    00106
    00110     public struct MatchOptions
    00111     {
    00112         public MatchType AdapterOrdinal;
    00113         public MatchType DeviceType;
    00114         public MatchType Windowed;
    00115         public MatchType AdapterFormat;
    00116         public MatchType VertexProcessing;
    00117         public MatchType Resolution;
    00118         public MatchType BackBufferFormat;
    00119         public MatchType BackBufferCount;
    00120         public MatchType MultiSample;
    00121         public MatchType SwapEffect;
    00122         public MatchType DepthFormat;
    00123         public MatchType StencilFormat;
    00124         public MatchType PresentFlags;
    00125         public MatchType RefreshRate;
    00126         public MatchType PresentInterval;
    00127     };
    00128     #endregion
    00129
    00130     #region Framework's data
    00134     class FrameworkData
    00135     {
    00136         #region Instance Data
    00137         private Device device; // the D3D rendering device
    00138
    00139         private DeviceSettings  currentDeviceSettings; // current device settings
    00140         private SurfaceDescription backBufferSurfaceDesc; // back buffer surface description
    00141         private Caps caps; // D3D caps for current device
    00142
    00143         private System.Windows.Forms.Control windowFocus; // the main app focus window
    00144         private System.Windows.Forms.Control windowDeviceFullScreen; // the main app device window in fullscreen mode
    00145         private System.Windows.Forms.Control windowDeviceWindowed; // the main app device window in windowed mode
    00146         private IntPtr adapterMonitor; // the monitor of the adapter
    00147         private double currentTime; // current time in seconds
    00148         private float elapsedTime; // time elapsed since last frame
    00149
    00150         private System.Windows.Forms.FormStartPosition defaultStartingLocation; // default starting location of the window
    00151         private System.Drawing.Rectangle clientRect; // client rect of window
    00152         private System.Drawing.Rectangle fullScreenClientRect; // client rect of window when fullscreen
    00153         private System.Drawing.Rectangle windowBoundsRect; // window rect of window
    00154         private System.Drawing.Point windowLocation; // Location of the window
    00155
    00156         private System.Windows.Forms.MainMenu windowMenu; // menu of app
    00157         private double lastStatsUpdateTime; // last time the stats were updated
    00158         private uint lastStatsUpdateFrames; // frames count since last time the stats were updated
    00159         private float frameRate; // frames per second
    00160         private int currentFrameNumber; // the current frame number
    00161
    00162         private bool isHandlingDefaultHotkeys; // if true, the sample framework will handle some default hotkeys
    00163         private bool isShowingMsgBoxOnError; // if true, then msgboxes are displayed upon errors
    00164         private bool isClipCursorWhenFullScreen; // if true, then the sample framework will keep the cursor from going outside the window when full screen
    00165         private bool isShowingCursorWhenFullScreen; // if true, then the sample framework will show a cursor when full screen
    00166         private bool isConstantFrameTime; // if true, then elapsed frame time will always be 0.05f seconds which is good for debugging or automated capture
    00167         private float timePerFrame; // the constant time per frame in seconds, only valid if isConstantFrameTime==true
    00168         private bool isInWireframeMode; // if true, then RenderState.FillMode==FillMode.WireFrame else RenderState.FillMode==FillMode.Solid
    00169         private bool canAutoChangeAdapter; // if true, then the adapter will automatically change if the window is different monitor
    00170         private bool isWindowCreatedWithDefaultPositions; // if true, then default was used and the window should be moved to the right adapter
    00171         private int applicationExitCode; // the exit code to be returned to the command line
    00172         private bool isHidingStats; // if true, then stats are being hidden
    00173
    00174         private bool isInited; // if true, then Init() has succeeded
    00175         private bool wasWindowCreated; // if true, then CreateWindow() or SetWindow() has succeeded
    00176         private bool wasDeviceCreated; // if true, then CreateDevice*() or SetDevice() has succeeded
    00177
    00178         private bool isInitCalled; // if true, then Init() was called
    00179         private bool isWindowCreateCalled; // if true, then CreateWindow() or SetWindow() was called
    00180         private bool isDeviceCreateCalled; // if true, then CreateDevice*() or SetDevice() was called
    00181
    00182         private bool isDeviceObjectsCreated; // if true, then DeviceCreated callback has been called (if non-NULL)
    00183         private bool isDeviceObjectsReset; // if true, then DeviceReset callback has been called (if non-NULL)
    00184         private bool isInsideDeviceCallback; // if true, then the framework is inside an app device callback
    00185         private bool isInsideMainloop; // if true, then the framework is inside the main loop
    00186         private bool isActive; // if true, then the app is the active top level window
    00187         private bool isTimePaused; // if true, then time is paused
    00188         private bool isRenderingPaused; // if true, then rendering is paused
    00189         private int pauseRenderingCount; // pause rendering ref count
    00190         private int pauseTimeCount; // pause time ref count
    00191         private bool isDeviceLost; // if true, then the device is lost and needs to be reset
    00192         private bool isMinimized; // if true, then the window is minimized
    00193         private bool isMaximized; // if true, then the window is maximized
    00194         private bool isSizeChangesIgnored; // if true, the sample framework won't reset the device upon window size change (for public use only)
    00195         private bool isNotifyOnMouseMove; // if true, include WM_MOUSEMOVE in mousecallback
    00196
    00197         private int overrideAdapterOrdinal; // if != -1, then override to use this adapter ordinal
    00198         private bool overrideWindowed; // if true, then force to start windowed
    00199         private bool overrideFullScreen; // if true, then force to start full screen
    00200         private int overrideStartX; // if != -1, then override to this X position of the window
    00201         private int overrideStartY; // if != -1, then override to this Y position of the window
    00202         private int overrideWidth; // if != 0, then override to this width
    00203         private int overrideHeight; // if != 0, then override to this height
    00204         private bool overrideForceHAL; // if true, then force to Hardware device (failing if one doesn't exist)
    00205         private bool overrideForceREF; // if true, then force to Reference device (failing if one doesn't exist)
    00206         private bool overrideForcePureHWVP; // if true, then force to use pure Hardware VertexProcessing (failing if device doesn't support it)
    00207         private bool overrideForceHWVP; // if true, then force to use Hardware VertexProcessing (failing if device doesn't support it)
    00208         private bool overrideForceSWVP; // if true, then force to use Software VertexProcessing
    00209         private bool overrideConstantFrameTime; // if true, then force to constant frame time
    00210         private float overrideConstantTimePerFrame; // the constant time per frame in seconds if overrideConstantFrameTime==true
    00211         private int overrideQuitAfterFrame; // if != 0, then it will force the app to quit after that frame
    00212
    00213         private IDeviceCreation deviceCallback; // Callback for device creation and acceptability
    00214         private IFrameworkCallback frameworkCallback; // Framework callback interface
    00215         private WndProcCallback wndFunc; // window messages callback
    00216
    00217         private SettingsDialog settings; // The settings dialog
    00218         private bool isShowingD3DSettingsDlg; // if true, then show the settings dialog
    00219
    00220         private ArrayList timerList = new ArrayList(); // list of TimerData structs
    00221         private string staticFrameStats; // static part of frames stats
    00222         private string frameStats; // frame stats (fps, width, etc)
    00223         private string deviceStats; // device stats (description, device type, etc)
    00224         private string windowTitle; // window title
    00225
    00226         #endregion
    00227
    00228         #region Properties
    00229         public Device Device { get { return device; } set {device = value; } }
    00230         public DeviceSettings CurrentDeviceSettings { get { return currentDeviceSettings; } set {currentDeviceSettings = value; } }
    00231         public SurfaceDescription BackBufferSurfaceDesc { get { return backBufferSurfaceDesc; } set {backBufferSurfaceDesc = value; } }
    00232         public Caps Caps { get { return caps; } set {caps = value; } }
    00233
    00234         public System.Windows.Forms.Control WindowFocus { get { return windowFocus; } set {windowFocus = value; } }
    00235         public System.Windows.Forms.Control WindowDeviceFullScreen { get { return windowDeviceFullScreen; } set {windowDeviceFullScreen = value; } }
    00236         public System.Windows.Forms.Control WindowDeviceWindowed { get { return windowDeviceWindowed; } set {windowDeviceWindowed = value; } }
    00237         public IntPtr AdapterMonitor { get { return adapterMonitor; } set {adapterMonitor = value; } }
    00238         public double CurrentTime { get { return currentTime; } set {currentTime = value; } }
    00239         public float ElapsedTime { get { return elapsedTime; } set {elapsedTime = value; } }
    00240
    00241         public System.Windows.Forms.FormStartPosition DefaultStartingLocation { get { return defaultStartingLocation; } set {defaultStartingLocation = value; } }
    00242         public System.Drawing.Rectangle ClientRectangle { get { return clientRect; } set {clientRect = value; } }
    00243         public System.Drawing.Rectangle FullScreenClientRectangle { get { return fullScreenClientRect; } set {fullScreenClientRect = value; } }
    00244         public System.Drawing.Rectangle WindowBoundsRectangle { get { return windowBoundsRect; } set {windowBoundsRect = value; } }
    00245         public System.Drawing.Point ClientLocation { get { return windowLocation; } set {windowLocation = value; } }
    00246         public System.Windows.Forms.MainMenu Menu { get { return windowMenu; } set {windowMenu = value; } }
    00247         public double LastStatsUpdateTime { get { return lastStatsUpdateTime; } set {lastStatsUpdateTime = value; } }
    00248         public uint LastStatsUpdateFrames { get { return lastStatsUpdateFrames; } set {lastStatsUpdateFrames = value; } }
    00249         public float CurrentFrameRate { get { return frameRate; } set {frameRate = value; } }
    00250         public int CurrentFrameNumber { get { return currentFrameNumber; } set {currentFrameNumber = value; } }
    00251
    00252         public bool IsHandlingDefaultHotkeys { get { return isHandlingDefaultHotkeys; } set {isHandlingDefaultHotkeys = value; } }
    00253         public bool IsShowingMsgBoxOnError { get { return isShowingMsgBoxOnError; } set {isShowingMsgBoxOnError = value; } }
    00254         public bool AreStatsHidden { get { return isHidingStats; } set {isHidingStats = value; } }
    00255         public bool IsCursorClippedWhenFullScreen { get { return isClipCursorWhenFullScreen; } set {isClipCursorWhenFullScreen = value; } }
    00256         public bool IsShowingCursorWhenFullScreen { get { return isShowingCursorWhenFullScreen; } set {isShowingCursorWhenFullScreen = value; } }
    00257         public bool IsUsingConstantFrameTime { get { return isConstantFrameTime; } set {isConstantFrameTime = value; } }
    00258         public float TimePerFrame { get { return timePerFrame; } set {timePerFrame = value; } }
    00259         public bool IsInWireframeMode { get { return isInWireframeMode; } set {isInWireframeMode = value; } }
    00260         public bool CanAutoChangeAdapter { get { return canAutoChangeAdapter; } set {canAutoChangeAdapter = value; } }
    00261         public bool IsWindowCreatedWithDefaultPositions { get { return isWindowCreatedWithDefaultPositions; } set {isWindowCreatedWithDefaultPositions = value; } }
    00262         public int ApplicationExitCode { get { return applicationExitCode; } set {applicationExitCode = value; } }
    00263
    00264         public bool IsInited { get { return isInited; } set {isInited = value; } }
    00265         public bool WasWindowCreated { get { return wasWindowCreated; } set {wasWindowCreated = value; } }
    00266         public bool WasDeviceCreated { get { return wasDeviceCreated; } set {wasDeviceCreated = value; } }
    00267
    00268         public bool WasInitCalled { get { return isInitCalled; } set {isInitCalled = value; } }
    00269         public bool WasWindowCreateCalled { get { return isWindowCreateCalled; } set {isWindowCreateCalled = value; } }
    00270         public bool WasDeviceCreateCalled { get { return isDeviceCreateCalled; } set {isDeviceCreateCalled = value; } }
    00271
    00272         public bool AreDeviceObjectsCreated { get { return isDeviceObjectsCreated; } set {isDeviceObjectsCreated = value; } }
    00273         public bool AreDeviceObjectsReset { get { return isDeviceObjectsReset; } set {isDeviceObjectsReset = value; } }
    00274         public bool IsInsideDeviceCallback { get { return isInsideDeviceCallback; } set {isInsideDeviceCallback = value; } }
    00275         public bool IsInsideMainloop { get { return isInsideMainloop; } set {isInsideMainloop = value; } }
    00276         public bool IsActive { get { return isActive; } set {isActive = value; } }
    00277         public bool IsTimePaused { get { return isTimePaused; } set {isTimePaused = value; } }
    00278         public bool IsRenderingPaused { get { return isRenderingPaused; } set {isRenderingPaused = value; } }
    00279         public int PauseRenderingCount { get { return pauseRenderingCount; } set {pauseRenderingCount = value; } }
    00280         public int PauseTimeCount { get { return pauseTimeCount; } set {pauseTimeCount = value; } }
    00281         public bool IsDeviceLost { get { return isDeviceLost; } set {isDeviceLost = value; } }
    00282         public bool IsMinimized { get { return isMinimized; } set {isMinimized = value; } }
    00283         public bool IsMaximized { get { return isMaximized; } set {isMaximized = value; } }
    00284         public bool AreSizeChangesIgnored { get { return isSizeChangesIgnored; } set {isSizeChangesIgnored = value; } }
    00285         public bool IsNotifiedOnMouseMove { get { return isNotifyOnMouseMove; } set {isNotifyOnMouseMove = value; } }
    00286
    00287         public int OverrideAdapterOrdinal { get { return overrideAdapterOrdinal; } set {overrideAdapterOrdinal = value; } }
    00288         public bool IsOverridingWindowed { get { return overrideWindowed; } set {overrideWindowed = value; } }
    00289         public bool IsOverridingFullScreen { get { return overrideFullScreen; } set {overrideFullScreen = value; } }
    00290         public int OverrideStartX { get { return overrideStartX; } set {overrideStartX = value; } }
    00291         public int OverrideStartY { get { return overrideStartY; } set {overrideStartY = value; } }
    00292         public int OverrideWidth { get { return overrideWidth; } set {overrideWidth = value; } }
    00293         public int OverrideHeight { get { return overrideHeight; } set {overrideHeight = value; } }
    00294         public bool IsOverridingForceHardware { get { return overrideForceHAL; } set {overrideForceHAL = value; } }
    00295         public bool IsOverridingForceReference { get { return overrideForceREF; } set {overrideForceREF = value; } }
    00296         public bool IsOverridingForcePureHardwareVertexProcessing { get { return overrideForcePureHWVP; } set {overrideForcePureHWVP = value; } }
    00297         public bool IsOverridingForceHardwareVertexProcessing { get { return overrideForceHWVP; } set {overrideForceHWVP = value; } }
    00298         public bool IsOverridingForceSoftwareVertexProcessing { get { return overrideForceSWVP; } set {overrideForceSWVP = value; } }
    00299         public bool IsOverridingConstantFrameTime { get { return overrideConstantFrameTime; } set {overrideConstantFrameTime = value; } }
    00300         public float OverrideConstantTimePerFrame { get { return overrideConstantTimePerFrame; } set {overrideConstantTimePerFrame = value; } }
    00301         public int OverrideQuitAfterFrame { get { return overrideQuitAfterFrame; } set {overrideQuitAfterFrame = value; } }
    00302
    00303         public IDeviceCreation DeviceCreationInterface { get { return deviceCallback; } set { deviceCallback = value; } }
    00304         public IFrameworkCallback CallbackInterface { get { return frameworkCallback; } set {frameworkCallback = value; } }
    00305         public WndProcCallback WndProcFunction { get { return wndFunc; } set {wndFunc = value; } }
    00306
    00307         public SettingsDialog Settings { get { return settings; } set {settings = value; } }
    00308         public bool IsD3DSettingsDialogShowing { get { return isShowingD3DSettingsDlg; } set {isShowingD3DSettingsDlg = value; } }
    00309
    00310         public ArrayList Timers { get { return timerList; } set {timerList = value; } }
    00311         public string StaticFrameStats { get { return staticFrameStats; } set {staticFrameStats = value; } }
    00312         public string FrameStats { get { return frameStats; } set {frameStats = value; } }
    00313         public string DeviceStats { get { return deviceStats; } set {deviceStats = value; } }
    00314         public string WindowTitle { get { return windowTitle; } set {windowTitle = value; } }
    00315         #endregion
    00316
    00320         public FrameworkData()
    00321         {
    00322             // Set some initial data
    00323             overrideStartX = -1;
    00324             overrideStartY = -1;
    00325             overrideAdapterOrdinal = -1;
    00326             canAutoChangeAdapter = true;
    00327             isShowingMsgBoxOnError = true;
    00328             isActive = true;
    00329             defaultStartingLocation = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation;
    00330         }
    00331     }
    00332     #endregion
    00333
    00334     #region Framework's Default Window
    00338     public class GraphicsWindow : System.Windows.Forms.Form
    00339     {
    00340         private Framework frame = null;
    00341         public GraphicsWindow(Framework f)
    00342         {
    00343             frame = f;
    00344             this.MinimumSize = Framework.MinWindowSize;
    00345         }
    00346
    00350         protected override void WndProc(ref Message m)
    00351         {
    00352             frame.WindowsProcedure(ref m);
    00353             base.WndProc (ref m);
    00354         }
    00355
    00356
    00357     }
    00358     #endregion
    00359 }