2008-01-05 18:11:29 +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
|
|
|
|
{
|
|
|
|
internal sealed class World3DShader : D3DShader
|
|
|
|
{
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Property handlers
|
|
|
|
private EffectHandle texture1;
|
|
|
|
private EffectHandle worldviewproj;
|
2008-11-17 00:41:52 +00:00
|
|
|
private EffectHandle minfiltersettings;
|
|
|
|
private EffectHandle magfiltersettings;
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2008-09-13 13:24:06 +00:00
|
|
|
public Matrix WorldViewProj { set { if(manager.Enabled) effect.SetValue<Matrix>(worldviewproj, value); } }
|
|
|
|
public Texture Texture1 { set { if(manager.Enabled) effect.SetTexture(texture1, value); } }
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// 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");
|
2008-11-17 00:41:52 +00:00
|
|
|
minfiltersettings = effect.GetParameter(null, "minfiltersettings");
|
|
|
|
magfiltersettings = effect.GetParameter(null, "magfiltersettings");
|
2008-01-05 18:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize world vertex declaration
|
|
|
|
VertexElement[] elements = new VertexElement[]
|
|
|
|
{
|
|
|
|
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),
|
|
|
|
VertexElement.VertexDeclarationEnd
|
|
|
|
};
|
|
|
|
vertexdecl = new VertexDeclaration(General.Map.Graphics.Device, 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(worldviewproj != null) worldviewproj.Dispose();
|
2008-11-17 00:41:52 +00:00
|
|
|
if(minfiltersettings != null) minfiltersettings.Dispose();
|
|
|
|
if(magfiltersettings != null) magfiltersettings.Dispose();
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2008-11-17 00:41:52 +00:00
|
|
|
// This sets the constant settings
|
|
|
|
public void SetConstants(bool bilinear, bool useanisotropic)
|
|
|
|
{
|
|
|
|
if(manager.Enabled)
|
|
|
|
{
|
|
|
|
if(bilinear)
|
|
|
|
{
|
|
|
|
effect.SetValue<int>(magfiltersettings, (int)TextureFilter.Linear);
|
|
|
|
if(useanisotropic) effect.SetValue<int>(minfiltersettings, (int)TextureFilter.Anisotropic);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
effect.SetValue<int>(magfiltersettings, (int)TextureFilter.Point);
|
|
|
|
effect.SetValue<int>(minfiltersettings, (int)TextureFilter.Point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|