// Disposer public virtual void Dispose() { // Not already disposed? if (!isdisposed) { // Clean up manager = null; if (effect != null) { effect.Dispose(); } vertexdecl.Dispose(); // Done isdisposed = true; } }
// Constructor public World3DShader(ShaderManager manager) : base(manager) { // Load effect from file effect = LoadEffect("world3d.fx"); // Get the property handlers from effect if (effect != null) { worldviewproj = effect.GetParameter(null, "worldviewproj"); texture1 = effect.GetParameter(null, "texture1"); minfiltersettings = effect.GetParameter(null, "minfiltersettings"); magfiltersettings = effect.GetParameter(null, "magfiltersettings"); mipfiltersettings = effect.GetParameter(null, "mipfiltersettings"); highlightcolor = effect.GetParameter(null, "highlightcolor"); maxanisotropysetting = effect.GetParameter(null, "maxanisotropysetting"); //mxd vertexColorHandle = effect.GetParameter(null, "vertexColor"); //lights lightPositionAndRadiusHandle = effect.GetParameter(null, "lightPosAndRadius"); lightColorHandle = effect.GetParameter(null, "lightColor"); ignoreNormalsHandle = effect.GetParameter(null, "ignoreNormals"); //fog camPosHandle = effect.GetParameter(null, "campos"); // [ZZ] stencilColorHandle = effect.GetParameter(null, "stencilColor"); world = effect.GetParameter(null, "world"); } // Initialize world vertex declaration VertexElement[] ve = { new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0), new VertexElement(0, 12, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0), new VertexElement(0, 16, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), new VertexElement(0, 24, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0), //mxd VertexElement.VertexDeclarationEnd }; vertexdecl = new VertexDeclaration(General.Map.Graphics.Device, ve); // We have no destructor GC.SuppressFinalize(this); }
// This initializes the graphics public bool Initialize() { PresentParameters displaypp; DeviceType devtype; // Use default adapter this.adapter = 0; // Manager.Adapters.Default.Adapter; try { // Make present parameters displaypp = CreatePresentParameters(adapter); // Determine device type for compatability with NVPerfHUD if (d3d.Adapters[adapter].Details.Description.EndsWith(NVPERFHUD_ADAPTER)) { devtype = DeviceType.Reference; } else { devtype = DeviceType.Hardware; } // Get the device capabilities devicecaps = d3d.GetDeviceCaps(adapter, devtype); // Check if this adapter supports TnL if ((devicecaps.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) { // Initialize with hardware TnL device = new Device(d3d, adapter, devtype, rendertarget.Handle, CreateFlags.HardwareVertexProcessing, displaypp); } else { // Initialize with software TnL device = new Device(d3d, adapter, devtype, rendertarget.Handle, CreateFlags.SoftwareVertexProcessing, displaypp); } } catch (Exception) { // Failed MessageBox.Show(General.MainWindow, "Unable to initialize the Direct3D video device. Another application may have taken exclusive mode on this video device or the device does not support Direct3D at all.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } // Add event to cancel resize event //device.DeviceResizing += new CancelEventHandler(CancelResize); // Keep a reference to the original buffers backbuffer = device.GetBackBuffer(0, 0); depthbuffer = device.DepthStencilSurface; // Get the viewport viewport = device.Viewport; // Create shader manager shaders = new ShaderManager(this); // Font postfilter = Filter.Box; font = new TextFont(); fonttexture = new ResourceImage("CodeImp.DoomBuilder.Resources.Font.png"); fonttexture.LoadImage(); fonttexture.MipMapLevels = 2; fonttexture.CreateTexture(); // Initialize settings SetupSettings(); // Done return(true); }
// This initializes the graphics public bool Initialize() { // Use default adapter this.adapter = 0; // Manager.Adapters.Default.Adapter; try { // Make present parameters PresentParameters displaypp = CreatePresentParameters(adapter); // Determine device type for compatability with NVPerfHUD DeviceType devtype; if (d3d.Adapters[adapter].Details.Description.EndsWith(NVPERFHUD_ADAPTER)) { devtype = DeviceType.Reference; } else { devtype = DeviceType.Hardware; } //mxd. Check maximum supported AA level... for (int i = AA_STEPS.Count - 1; i > 0; i--) { if (General.Settings.AntiAliasingSamples < AA_STEPS[i]) { continue; } if (d3d.CheckDeviceMultisampleType(this.adapter, devtype, d3d.Adapters[adapter].CurrentDisplayMode.Format, displaypp.Windowed, (MultisampleType)AA_STEPS[i])) { break; } if (General.Settings.AntiAliasingSamples > AA_STEPS[i - 1]) { General.Settings.AntiAliasingSamples = AA_STEPS[i - 1]; // TODO: looks like setting Multisample here just resets it to MultisampleType.None, // regardless of value in displaypp.Multisample. Why?.. displaypp.Multisample = (MultisampleType)General.Settings.AntiAliasingSamples; } } // Get the device capabilities devicecaps = d3d.GetDeviceCaps(adapter, devtype); // Check if this adapter supports TnL if ((devicecaps.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) { // Initialize with hardware TnL device = new Device(d3d, adapter, devtype, rendertarget.Handle, CreateFlags.HardwareVertexProcessing, displaypp); } else { // Initialize with software TnL device = new Device(d3d, adapter, devtype, rendertarget.Handle, CreateFlags.SoftwareVertexProcessing, displaypp); } } catch (Exception) { // Failed MessageBox.Show(General.MainWindow, "Unable to initialize the Direct3D video device. Another application may have taken exclusive mode on this video device or the device does not support Direct3D at all.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //mxd. Check if we can use shaders if (device.Capabilities.PixelShaderVersion.Major < 2) { // Failed MessageBox.Show(General.MainWindow, "Unable to initialize the Direct3D video device. Video device with Shader Model 2.0 support is required.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } // Add event to cancel resize event //device.DeviceResizing += new CancelEventHandler(CancelResize); // Keep a reference to the original buffers backbuffer = device.GetBackBuffer(0, 0); depthbuffer = device.DepthStencilSurface; // Get the viewport viewport = device.Viewport; // Create shader manager shaders = new ShaderManager(this); // Initialize settings SetupSettings(); // Done return(true); }