2007-10-19 17:05:21 +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;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using SlimDX.Direct3D9;
|
|
|
|
using SlimDX;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Rendering
|
|
|
|
{
|
2008-01-02 21:49:43 +00:00
|
|
|
internal class ShaderManager : ID3DResource
|
2007-10-19 17:05:21 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Settings
|
|
|
|
private string shadertechnique;
|
|
|
|
private bool useshaders;
|
|
|
|
|
|
|
|
// Shaders
|
2007-10-23 05:08:02 +00:00
|
|
|
private Display2DShader display2dshader;
|
2007-10-21 04:07:36 +00:00
|
|
|
private Things2DShader things2dshader;
|
2008-01-05 18:11:29 +00:00
|
|
|
private World3DShader world3dshader;
|
2007-10-19 17:05:21 +00:00
|
|
|
|
2007-10-31 20:34:09 +00:00
|
|
|
// Device
|
|
|
|
private D3DDevice device;
|
|
|
|
|
2007-10-19 17:05:21 +00:00
|
|
|
// Disposing
|
|
|
|
private bool isdisposed = false;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public bool Enabled { get { return useshaders; } }
|
|
|
|
public string ShaderTechnique { get { return shadertechnique; } }
|
2007-10-23 05:08:02 +00:00
|
|
|
public Display2DShader Display2D { get { return display2dshader; } }
|
2007-10-21 04:07:36 +00:00
|
|
|
public Things2DShader Things2D { get { return things2dshader; } }
|
2008-01-05 18:11:29 +00:00
|
|
|
public World3DShader World3D { get { return world3dshader; } }
|
2007-10-19 17:05:21 +00:00
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
2008-05-18 11:43:28 +00:00
|
|
|
internal D3DDevice D3DDevice { get { return device; } }
|
2007-10-19 17:05:21 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2007-10-31 20:34:09 +00:00
|
|
|
public ShaderManager(D3DDevice device)
|
2007-10-19 17:05:21 +00:00
|
|
|
{
|
2007-10-31 20:34:09 +00:00
|
|
|
// Initialize
|
|
|
|
this.device = device;
|
2007-10-19 17:05:21 +00:00
|
|
|
|
2007-10-31 20:34:09 +00:00
|
|
|
// Load
|
|
|
|
ReloadResource();
|
|
|
|
|
|
|
|
// Register as resource
|
|
|
|
device.RegisterResource(this);
|
2007-10-19 17:05:21 +00:00
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// Disposer
|
2007-10-19 17:05:21 +00:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
2007-10-31 20:34:09 +00:00
|
|
|
UnloadResource();
|
|
|
|
|
|
|
|
// Unregister as resource
|
|
|
|
device.UnregisterResource(this);
|
2007-10-19 17:05:21 +00:00
|
|
|
|
|
|
|
// Done
|
2007-10-31 20:34:09 +00:00
|
|
|
device = null;
|
2007-10-19 17:05:21 +00:00
|
|
|
isdisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-10-31 20:34:09 +00:00
|
|
|
|
|
|
|
#region ================== Resources
|
|
|
|
|
|
|
|
// Clean up resources
|
|
|
|
public void UnloadResource()
|
|
|
|
{
|
|
|
|
display2dshader.Dispose();
|
|
|
|
things2dshader.Dispose();
|
2008-01-05 18:11:29 +00:00
|
|
|
world3dshader.Dispose();
|
2007-10-31 20:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load resources
|
|
|
|
public void ReloadResource()
|
|
|
|
{
|
|
|
|
Capabilities caps;
|
|
|
|
|
|
|
|
// Check if we can use shaders
|
2008-05-11 00:42:34 +00:00
|
|
|
caps = General.Map.Graphics.Device.Capabilities;
|
2007-10-31 20:34:09 +00:00
|
|
|
useshaders = (caps.PixelShaderVersion.Major >= 2);
|
|
|
|
shadertechnique = "SM20";
|
|
|
|
|
|
|
|
// Initialize effects
|
|
|
|
display2dshader = new Display2DShader(this);
|
|
|
|
things2dshader = new Things2DShader(this);
|
2008-01-05 18:11:29 +00:00
|
|
|
world3dshader = new World3DShader(this);
|
2007-10-31 20:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-10-19 17:05:21 +00:00
|
|
|
}
|
|
|
|
}
|