UltimateZoneBuilder/Source/Core/Rendering/Things2DShader.cs

149 lines
4 KiB
C#
Raw Normal View History

#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;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
2019-08-09 21:22:16 +00:00
internal sealed class Things2DShader : EffectShader
{
#region ================== Variables
// Property handlers
private readonly EffectHandle texture1;
private readonly EffectHandle rendersettings;
private readonly EffectHandle transformsettings;
private readonly EffectHandle fillcolor; //mxd
private readonly EffectHandle desaturationHandle; // [ZZ]
2012-04-17 19:13:47 +00:00
#endregion
#region ================== Properties
public Texture Texture1 { set { effect.SetTexture(texture1, value); settingschanged = true; } }
//mxd
private Color4 fc;
public Color4 FillColor
{
set
{
if(fc != value)
{
effect.SetValue(fillcolor, value);
fc = value;
settingschanged = true;
}
}
}
// [ZZ]
private float desaturation;
public float Desaturation
{
set
{
if (desaturation != value)
{
effect.SetValue(desaturationHandle, value);
desaturation = value;
settingschanged = true;
}
}
}
#endregion
#region ================== Constructor / Disposer
// Constructor
public Things2DShader(ShaderManager manager) : base(manager)
{
// Load effect from file
effect = LoadEffect("things2d.fx");
// Get the property handlers from effect
if(effect != null)
{
texture1 = effect.GetParameter(null, "texture1");
rendersettings = effect.GetParameter(null, "rendersettings");
transformsettings = effect.GetParameter(null, "transformsettings");
fillcolor = effect.GetParameter(null, "fillColor"); //mxd
desaturationHandle = effect.GetParameter(null, "desaturation"); // [ZZ]
}
// Initialize world vertex declaration
VertexElement[] elements = new[]
{
2019-08-08 01:51:21 +00:00
new VertexElement(0, 0, DeclarationType.Float3, DeclarationUsage.Position),
new VertexElement(0, 12, DeclarationType.Color, DeclarationUsage.Color),
new VertexElement(0, 16, DeclarationType.Float2, DeclarationUsage.TextureCoordinate)
};
2019-08-08 01:19:11 +00:00
vertexdecl = new VertexDeclaration(elements);
// We have no destructor
GC.SuppressFinalize(this);
}
// Disposer
public override void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
if(texture1 != null) texture1.Dispose();
if(rendersettings != null) rendersettings.Dispose();
if(transformsettings != null) transformsettings.Dispose();
if(fillcolor != null) fillcolor.Dispose(); //mxd
if(desaturationHandle != null) desaturationHandle.Dispose();
// Done
base.Dispose();
}
}
#endregion
#region ================== Methods
// This sets the settings
public void SetSettings(float alpha)
{
Vector4 values = new Vector4(0.0f, 0.0f, 1.0f, alpha);
effect.SetValue(rendersettings, values);
2019-08-08 01:19:11 +00:00
Matrix world = manager.D3DDevice.GetTransform(TransformState.World);
Matrix view = manager.D3DDevice.GetTransform(TransformState.View);
effect.SetValue(transformsettings, world * view);
settingschanged = true; //mxd
}
2012-04-17 19:13:47 +00:00
//mxd. Used to render models
public void SetTransformSettings(Matrix world)
{
2019-08-08 01:19:11 +00:00
Matrix view = manager.D3DDevice.GetTransform(TransformState.View);
effect.SetValue(transformsettings, world * view);
settingschanged = true;
}
#endregion
}
}