2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Copyright ( c ) 2007 Pascal vd Heiden
/ *
* Copyright ( c ) 2007 Pascal vd Heiden , www . codeimp . com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* /
#endregion
#region = = = = = = = = = = = = = = = = = = Namespaces
using System ;
using System.Collections.Generic ;
using System.Drawing ;
2016-02-06 00:04:02 +00:00
using System.Windows.Forms ;
using CodeImp.DoomBuilder.Controls ;
2009-04-19 18:07:22 +00:00
using CodeImp.DoomBuilder.Geometry ;
using SlimDX ;
2016-02-06 00:04:02 +00:00
using SlimDX.Direct3D9 ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
2016-02-01 22:04:00 +00:00
internal class D3DDevice : IDisposable
2009-04-19 18:07:22 +00:00
{
#region = = = = = = = = = = = = = = = = = = Constants
// NVPerfHUD device name
2016-03-25 14:06:00 +00:00
private const string NVPERFHUD_ADAPTER = "NVPerfHUD" ;
//mxd. Anisotropic filtering steps
public static readonly List < float > AF_STEPS = new List < float > { 1.0f , 2.0f , 4.0f , 8.0f , 16.0f } ;
//mxd. Antialiasing steps
public static readonly List < int > AA_STEPS = new List < int > { 0 , 2 , 4 , 8 } ;
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Variables
// Settings
private int adapter ;
private Filter postfilter ;
private Filter mipgeneratefilter ;
2015-09-17 12:02:39 +00:00
private static bool isrendering ; //mxd
2009-04-19 18:07:22 +00:00
// Main objects
private static Direct3D d3d ;
private RenderTargetControl rendertarget ;
private Capabilities devicecaps ;
private Device device ;
private Viewport viewport ;
2016-02-01 22:04:00 +00:00
private readonly HashSet < ID3DResource > resources ;
2009-04-19 18:07:22 +00:00
private ShaderManager shaders ;
private Surface backbuffer ;
private Surface depthbuffer ;
// Disposing
2014-02-21 14:42:12 +00:00
private bool isdisposed ;
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
internal Device Device { get { return device ; } }
public bool IsDisposed { get { return isdisposed ; } }
2015-09-17 12:02:39 +00:00
public static bool IsRendering { get { return isrendering ; } } //mxd
2009-04-19 18:07:22 +00:00
internal RenderTargetControl RenderTarget { get { return rendertarget ; } }
internal Viewport Viewport { get { return viewport ; } }
internal ShaderManager Shaders { get { return shaders ; } }
internal Surface BackBuffer { get { return backbuffer ; } }
internal Surface DepthBuffer { get { return depthbuffer ; } }
internal Filter PostFilter { get { return postfilter ; } }
internal Filter MipGenerateFilter { get { return mipgeneratefilter ; } }
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor / Disposer
// Constructor
internal D3DDevice ( RenderTargetControl rendertarget )
{
// Set render target
this . rendertarget = rendertarget ;
// Create resources list
2016-02-01 22:04:00 +00:00
resources = new HashSet < ID3DResource > ( ) ;
2009-04-19 18:07:22 +00:00
// We have no destructor
GC . SuppressFinalize ( this ) ;
}
// Disposer
2016-02-01 22:04:00 +00:00
public void Dispose ( )
2009-04-19 18:07:22 +00:00
{
// Not already disposed?
if ( ! isdisposed )
{
// Clean up
2016-02-01 22:04:00 +00:00
foreach ( ID3DResource res in resources ) res . UnloadResource ( ) ;
2009-04-19 18:07:22 +00:00
if ( shaders ! = null ) shaders . Dispose ( ) ;
rendertarget = null ;
if ( backbuffer ! = null ) backbuffer . Dispose ( ) ;
if ( depthbuffer ! = null ) depthbuffer . Dispose ( ) ;
2016-02-06 00:04:02 +00:00
if ( device ! = null ) device . Dispose ( ) ;
if ( ObjectTable . Objects . Count > 1 ) //mxd. Direct3D itself is not disposed while the editor is running
{
//mxd. Get rid of any remaining D3D objects...
foreach ( ComObject o in ObjectTable . Objects )
{
if ( o is Direct3D ) continue ; // Don't dispose the device itself...
General . WriteLogLine ( "WARNING: D3D resource " + o
+ ( o . Tag ! = null ? " (" + o . Tag + ")" : string . Empty ) + " was not disposed properly!"
+ ( o . CreationSource ! = null ? " Stack trace: " + o . CreationSource : string . Empty ) ) ;
o . Dispose ( ) ;
}
#if DEBUG
General . ShowWarningMessage ( "Some D3D resources were not disposed properly! See the event log for more details." ,
MessageBoxButtons . OK ) ;
#endif
}
2009-04-19 18:07:22 +00:00
// Done
2016-02-06 00:04:02 +00:00
isrendering = false ; //mxd
2009-04-19 18:07:22 +00:00
isdisposed = true ;
}
}
#endregion
#region = = = = = = = = = = = = = = = = = = Renderstates
// This completes initialization after the device has started or has been reset
public void SetupSettings ( )
{
// Setup renderstates
device . SetRenderState ( RenderState . AlphaBlendEnable , false ) ;
device . SetRenderState ( RenderState . AlphaBlendEnable , false ) ;
device . SetRenderState ( RenderState . AlphaFunc , Compare . GreaterEqual ) ;
device . SetRenderState ( RenderState . AlphaRef , 0x0000007E ) ;
device . SetRenderState ( RenderState . AlphaTestEnable , false ) ;
device . SetRenderState ( RenderState . Ambient , Color . White . ToArgb ( ) ) ;
device . SetRenderState ( RenderState . AmbientMaterialSource , ColorSource . Material ) ;
device . SetRenderState ( RenderState . AntialiasedLineEnable , false ) ;
device . SetRenderState ( RenderState . Clipping , true ) ;
device . SetRenderState ( RenderState . ColorVertex , false ) ;
device . SetRenderState ( RenderState . ColorWriteEnable , ColorWriteEnable . Red | ColorWriteEnable . Green | ColorWriteEnable . Blue | ColorWriteEnable . Alpha ) ;
device . SetRenderState ( RenderState . CullMode , Cull . None ) ;
device . SetRenderState ( RenderState . DestinationBlend , Blend . InverseSourceAlpha ) ;
device . SetRenderState ( RenderState . DiffuseMaterialSource , ColorSource . Color1 ) ;
2016-02-02 21:07:15 +00:00
//device.SetRenderState(RenderState.DitherEnable, true);
2009-04-19 18:07:22 +00:00
device . SetRenderState ( RenderState . FillMode , FillMode . Solid ) ;
device . SetRenderState ( RenderState . FogEnable , false ) ;
device . SetRenderState ( RenderState . FogTableMode , FogMode . Linear ) ;
device . SetRenderState ( RenderState . Lighting , false ) ;
device . SetRenderState ( RenderState . LocalViewer , false ) ;
2016-03-25 14:06:00 +00:00
device . SetRenderState ( RenderState . MultisampleAntialias , ( General . Settings . AntiAliasingSamples > 0 ) ) ; //mxd
2009-04-19 18:07:22 +00:00
device . SetRenderState ( RenderState . NormalizeNormals , false ) ;
device . SetRenderState ( RenderState . PointSpriteEnable , false ) ;
device . SetRenderState ( RenderState . RangeFogEnable , false ) ;
2016-03-08 20:37:44 +00:00
device . SetRenderState ( RenderState . ShadeMode , ShadeMode . Gouraud ) ;
2009-04-19 18:07:22 +00:00
device . SetRenderState ( RenderState . SourceBlend , Blend . SourceAlpha ) ;
device . SetRenderState ( RenderState . SpecularEnable , false ) ;
device . SetRenderState ( RenderState . StencilEnable , false ) ;
device . SetRenderState ( RenderState . TextureFactor , - 1 ) ;
device . SetRenderState ( RenderState . ZEnable , false ) ;
device . SetRenderState ( RenderState . ZWriteEnable , false ) ;
device . PixelShader = null ;
device . VertexShader = null ;
// Matrices
device . SetTransform ( TransformState . World , Matrix . Identity ) ;
device . SetTransform ( TransformState . View , Matrix . Identity ) ;
device . SetTransform ( TransformState . Projection , Matrix . Identity ) ;
// Texture addressing
device . SetSamplerState ( 0 , SamplerState . AddressU , TextureAddress . Wrap ) ;
device . SetSamplerState ( 0 , SamplerState . AddressV , TextureAddress . Wrap ) ;
device . SetSamplerState ( 0 , SamplerState . AddressW , TextureAddress . Wrap ) ;
// Setup material
2016-01-14 22:15:54 +00:00
device . Material = new Material {
Ambient = new Color4 ( Color . White ) ,
Diffuse = new Color4 ( Color . White ) ,
Specular = new Color4 ( Color . White )
} ;
2009-04-19 18:07:22 +00:00
// Shader settings
2016-03-25 14:06:00 +00:00
shaders . World3D . SetConstants ( General . Settings . VisualBilinear , Math . Min ( devicecaps . MaxAnisotropy , General . Settings . FilterAnisotropy ) ) ;
2009-04-19 18:07:22 +00:00
// Texture filters
2009-05-03 20:21:52 +00:00
postfilter = Filter . Point ;
mipgeneratefilter = Filter . Box ;
2009-04-19 18:07:22 +00:00
// Initialize presentations
Presentation . Initialize ( ) ;
}
#endregion
#region = = = = = = = = = = = = = = = = = = Initialization
// This starts up Direct3D
public static void Startup ( )
{
d3d = new Direct3D ( ) ;
}
// This terminates Direct3D
public static void Terminate ( )
{
if ( d3d ! = null )
{
d3d . Dispose ( ) ;
d3d = null ;
}
}
// This initializes the graphics
public bool Initialize ( )
{
// Use default adapter
this . adapter = 0 ; // Manager.Adapters.Default.Adapter;
2009-05-04 07:46:44 +00:00
try
{
// Make present parameters
2015-12-28 15:01:53 +00:00
PresentParameters displaypp = CreatePresentParameters ( adapter ) ;
2009-04-19 18:07:22 +00:00
2009-05-04 07:46:44 +00:00
// Determine device type for compatability with NVPerfHUD
2015-12-28 15:01:53 +00:00
DeviceType devtype ;
2009-05-04 07:46:44 +00:00
if ( d3d . Adapters [ adapter ] . Details . Description . EndsWith ( NVPERFHUD_ADAPTER ) )
devtype = DeviceType . Reference ;
else
devtype = DeviceType . Hardware ;
2009-04-19 18:07:22 +00:00
2016-03-25 14:06:00 +00:00
//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 ;
}
}
2009-05-04 07:46:44 +00:00
// Get the device capabilities
devicecaps = d3d . GetDeviceCaps ( adapter , devtype ) ;
2009-04-19 18:07:22 +00:00
// 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
2009-05-04 07:46:44 +00:00
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 ) ;
2009-04-19 18:07:22 +00:00
return false ;
}
2016-01-14 22:15:54 +00:00
//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 ;
}
2009-04-19 18:07:22 +00:00
// 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 ;
}
// This is to disable the automatic resize reset
2013-07-19 15:30:58 +00:00
/ * private static void CancelResize ( object sender , CancelEventArgs e )
2009-04-19 18:07:22 +00:00
{
// Cancel resize event
e . Cancel = true ;
2013-07-19 15:30:58 +00:00
} * /
2009-04-19 18:07:22 +00:00
// This creates present parameters
private PresentParameters CreatePresentParameters ( int adapter )
{
PresentParameters displaypp = new PresentParameters ( ) ;
2014-09-17 12:46:47 +00:00
2009-04-19 18:07:22 +00:00
// Get current display mode
2014-09-17 12:46:47 +00:00
DisplayMode currentmode = d3d . Adapters [ adapter ] . CurrentDisplayMode ;
2009-04-19 18:07:22 +00:00
// Make present parameters
displaypp . Windowed = true ;
displaypp . SwapEffect = SwapEffect . Discard ;
displaypp . BackBufferCount = 1 ;
displaypp . BackBufferFormat = currentmode . Format ;
displaypp . BackBufferWidth = rendertarget . ClientSize . Width ;
displaypp . BackBufferHeight = rendertarget . ClientSize . Height ;
displaypp . EnableAutoDepthStencil = true ;
2016-02-06 00:04:02 +00:00
displaypp . AutoDepthStencilFormat = Format . D24X8 ; //Format.D16;
2016-03-25 14:06:00 +00:00
displaypp . Multisample = ( MultisampleType ) General . Settings . AntiAliasingSamples ;
2009-04-19 18:07:22 +00:00
displaypp . PresentationInterval = PresentInterval . Immediate ;
// Return result
return displaypp ;
}
#endregion
#region = = = = = = = = = = = = = = = = = = Resetting
// This registers a resource
internal void RegisterResource ( ID3DResource res )
{
// Add resource
2016-02-01 22:04:00 +00:00
resources . Add ( res ) ;
2009-04-19 18:07:22 +00:00
}
// This unregisters a resource
internal void UnregisterResource ( ID3DResource res )
{
// Remove resource
resources . Remove ( res ) ;
}
// This resets the device and returns true on success
internal bool Reset ( )
{
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
// Unload all Direct3D resources
2016-02-01 22:04:00 +00:00
foreach ( ID3DResource res in resources ) res . UnloadResource ( ) ;
2009-04-19 18:07:22 +00:00
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
// Lose backbuffers
if ( backbuffer ! = null ) backbuffer . Dispose ( ) ;
if ( depthbuffer ! = null ) depthbuffer . Dispose ( ) ;
backbuffer = null ;
depthbuffer = null ;
2009-04-19 18:07:22 +00:00
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
try
{
// Make present parameters
PresentParameters displaypp = CreatePresentParameters ( adapter ) ;
// Reset the device
device . Reset ( displaypp ) ;
}
2014-09-17 13:16:11 +00:00
#if DEBUG
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
catch ( Exception e )
{
// Failed to re-initialize
Console . WriteLine ( "Device reset failed: " + e . Message ) ;
return false ;
}
2014-09-17 13:16:11 +00:00
#else
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
catch ( Exception )
{
// Failed to re-initialize
return false ;
}
2014-09-17 13:16:11 +00:00
#endif
2009-04-19 18:07:22 +00:00
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
// Keep a reference to the original buffers
backbuffer = device . GetBackBuffer ( 0 , 0 ) ;
depthbuffer = device . DepthStencilSurface ;
2009-04-19 18:07:22 +00:00
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
// Get the viewport
viewport = device . Viewport ;
2009-04-19 18:07:22 +00:00
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
// Reload all Direct3D resources
2016-02-01 22:04:00 +00:00
foreach ( ID3DResource res in resources ) res . ReloadResource ( ) ;
2009-04-19 18:07:22 +00:00
Game Configurations: added Vanilla Strife, Vanilla Heretic and Vanilla Hexen game configurations.
Added "makedoorceil" game configuration property. Works the same way as "makedoortrack" and "makedoordoor", but for ceilings of door sectors.
Changed, Game configurations: the editor no longer tries to load DECORATE/MODELDEF/VOXELDEF/GLDEFS/REVERBS lumps when "decorategames" setting is not specified / is set to empty string.
Changed, General interface: "Tools -> Reload MODELDEF/VOXELDEF" and "Tools -> Reload GLDEFS" menu items are no longer shown when current game configuration doesn't support DECORATE.
Fixed a crash when pasting linedef/thing properties in Hexen map format.
Fixed, Visual mode: Visual Thing resources were not fully unloaded when resetting D3D device leading to crash when switching to the editor from a DX-using game engine (like ZDoom) running in fullscreen.
Fixed: in some cases, when current game configuration supported multiple script compilers, it was possible to open/create a map or change map options without selecting any script compiler.
Fixed, New Map Options window: default map name was not updated when switching game configurations.
Fixed: copied map element properties were not reset after switching to another map.
Fixed: stored textures for "Make Door" action were not reset after switching to another map.
Fixed, Game Configurations window: currently selected test engine name was not updated when pasting test engines from another configuration.
Fixed, Game Configurations: all "Heretic in Doom map format" configurations were using Doom sector effects list.
Fixed, Game Configurations: all "Strife in Doom map format" configurations were using Doom sector effects list.
2015-10-21 13:35:42 +00:00
// Re-apply settings
SetupSettings ( ) ;
// Success
return true ;
2009-04-19 18:07:22 +00:00
}
#endregion
#region = = = = = = = = = = = = = = = = = = Rendering
// This begins a drawing session
public bool StartRendering ( bool clear , Color4 backcolor , Surface target , Surface depthbuffer )
{
// Check if we can render
2015-09-17 12:02:39 +00:00
if ( CheckAvailability ( ) & & ! isrendering ) //mxd. Added isrendering check
2009-04-19 18:07:22 +00:00
{
// Set rendertarget
device . DepthStencilSurface = depthbuffer ;
device . SetRenderTarget ( 0 , target ) ;
// Clear the screen
if ( clear )
{
if ( depthbuffer ! = null )
device . Clear ( ClearFlags . Target | ClearFlags . ZBuffer , backcolor , 1f , 0 ) ;
else
device . Clear ( ClearFlags . Target , backcolor , 1f , 0 ) ;
}
// Ready to render
device . BeginScene ( ) ;
2015-09-17 12:02:39 +00:00
isrendering = true ; //mxd
2009-04-19 18:07:22 +00:00
return true ;
}
else
{
// Minimized, you cannot see anything
2015-09-17 12:02:39 +00:00
isrendering = false ; //mxd
2009-04-19 18:07:22 +00:00
return false ;
}
}
2009-05-14 19:23:27 +00:00
// This clears a target
public void ClearRendertarget ( Color4 backcolor , Surface target , Surface depthbuffer )
{
// Set rendertarget
device . DepthStencilSurface = depthbuffer ;
device . SetRenderTarget ( 0 , target ) ;
if ( depthbuffer ! = null )
device . Clear ( ClearFlags . Target | ClearFlags . ZBuffer , backcolor , 1f , 0 ) ;
else
device . Clear ( ClearFlags . Target , backcolor , 1f , 0 ) ;
}
2009-04-19 18:07:22 +00:00
// This ends a drawing session
public void FinishRendering ( )
{
try
{
// Done
device . EndScene ( ) ;
2015-09-17 12:02:39 +00:00
isrendering = false ; //mxd
2009-04-19 18:07:22 +00:00
}
// Errors are not a problem here
catch ( Exception ) { }
}
// This presents what has been drawn
public void Present ( )
{
try
{
device . Present ( ) ;
2015-09-17 12:02:39 +00:00
isrendering = false ; //mxd
2009-04-19 18:07:22 +00:00
}
// Errors are not a problem here
catch ( Exception ) { }
}
// This checks if we can use the hardware at this moment
public bool CheckAvailability ( )
{
// When minimized, the hardware is not available
if ( General . MainWindow . WindowState ! = FormWindowState . Minimized )
{
// Test the cooperative level
Result coopresult = device . TestCooperativeLevel ( ) ;
// Check if device must be reset
if ( ! coopresult . IsSuccess )
{
// Should we reset?
if ( coopresult . Name = = "D3DERR_DEVICENOTRESET" )
{
// Device is lost and must be reset now
Reset ( ) ;
}
// Impossible to render at this point
return false ;
}
else
{
2014-09-17 12:46:47 +00:00
// Ready to go!
2009-04-19 18:07:22 +00:00
return true ;
}
}
else
{
// Minimized
return false ;
}
}
#endregion
#region = = = = = = = = = = = = = = = = = = Tools
// Make a color from ARGB
public static int ARGB ( float a , float r , float g , float b )
{
return Color . FromArgb ( ( int ) ( a * 255f ) , ( int ) ( r * 255f ) , ( int ) ( g * 255f ) , ( int ) ( b * 255f ) ) . ToArgb ( ) ;
}
// Make a color from RGB
public static int RGB ( int r , int g , int b )
{
return Color . FromArgb ( 255 , r , g , b ) . ToArgb ( ) ;
}
// This makes a Vector3 from Vector3D
public static Vector3 V3 ( Vector3D v3d )
{
return new Vector3 ( v3d . x , v3d . y , v3d . z ) ;
}
// This makes a Vector3D from Vector3
public static Vector3D V3D ( Vector3 v3 )
{
return new Vector3D ( v3 . X , v3 . Y , v3 . Z ) ;
}
2010-01-30 20:46:51 +00:00
// This makes a Vector2 from Vector2D
public static Vector2 V2 ( Vector2D v2d )
{
return new Vector2 ( v2d . x , v2d . y ) ;
}
// This makes a Vector2D from Vector2
public static Vector2D V2D ( Vector2 v2 )
{
return new Vector2D ( v2 . X , v2 . Y ) ;
}
2009-04-19 18:07:22 +00:00
#endregion
}
}