mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-26 22:01:45 +00:00
things! incomplete though.
This commit is contained in:
parent
109e4a4690
commit
b8e7370db6
21 changed files with 630 additions and 65 deletions
BIN
Resources/ThingArrow.png
Normal file
BIN
Resources/ThingArrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
Resources/ThingCircle.png
Normal file
BIN
Resources/ThingCircle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
BIN
Resources/ThingMask.png
Normal file
BIN
Resources/ThingMask.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 942 B |
BIN
Resources/ThingTexture1.png
Normal file
BIN
Resources/ThingTexture1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
Resources/ThingTexture2.png
Normal file
BIN
Resources/ThingTexture2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -51,6 +51,7 @@
|
|||
<Compile Include="Data\FlatImage.cs" />
|
||||
<Compile Include="Data\PatchNames.cs" />
|
||||
<Compile Include="Data\Playpal.cs" />
|
||||
<Compile Include="Data\ResourceImage.cs" />
|
||||
<Compile Include="Data\SpriteImage.cs" />
|
||||
<Compile Include="Data\TextureImage.cs" />
|
||||
<Compile Include="Editing\EditMode.cs" />
|
||||
|
@ -177,6 +178,7 @@
|
|||
<Compile Include="Rendering\Renderer2D.cs" />
|
||||
<Compile Include="Rendering\Renderer3D.cs" />
|
||||
<Compile Include="Rendering\ShaderManager.cs" />
|
||||
<Compile Include="Rendering\Things2DShader.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="SlimDX, Version=1.0.2847.35002, Culture=neutral, processorArchitecture=x86" />
|
||||
|
@ -248,6 +250,8 @@
|
|||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Resources\Actions.cfg" />
|
||||
<EmbeddedResource Include="Resources\base2d.fx" />
|
||||
<EmbeddedResource Include="Resources\Thing2D.png" />
|
||||
<EmbeddedResource Include="Resources\things2d.fx" />
|
||||
<None Include="Resources\Splash2.png" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -26,6 +26,7 @@ using SlimDX.Direct3D9;
|
|||
using System.Drawing.Imaging;
|
||||
using CodeImp.DoomBuilder.Rendering;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using System.IO;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -149,7 +150,19 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// This creates the Direct3D texture
|
||||
public void CreateTexture()
|
||||
{
|
||||
// TODO: Write to memory stream and read with Texture.FromStream
|
||||
MemoryStream memstream;
|
||||
|
||||
// Only do this when texture is not created yet
|
||||
if(texture == null)
|
||||
{
|
||||
// Write to memory stream and read from memory
|
||||
memstream = new MemoryStream();
|
||||
bitmap.Save(memstream, ImageFormat.Bmp);
|
||||
memstream.Seek(0, SeekOrigin.Begin);
|
||||
texture = Texture.FromStream(General.Map.Graphics.Device, memstream, (int)memstream.Length, bitmap.Size.Width, bitmap.Size.Height, 0,
|
||||
Usage.None, Format.Unknown, Pool.Managed, Filter.Box, Filter.Box, 0);
|
||||
memstream.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// This destroys the Direct3D texture
|
||||
|
|
92
Source/Data/ResourceImage.cs
Normal file
92
Source/Data/ResourceImage.cs
Normal file
|
@ -0,0 +1,92 @@
|
|||
|
||||
#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.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using CodeImp.DoomBuilder.Rendering;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using System.IO;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Data
|
||||
{
|
||||
internal class ResourceImage : ImageData
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
public ResourceImage(string resourcename)
|
||||
{
|
||||
// Initialize
|
||||
SetName(resourcename);
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
public override void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
if(!isdisposed)
|
||||
{
|
||||
// Clean up
|
||||
|
||||
// Done
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This loads the image
|
||||
public override void LoadImage()
|
||||
{
|
||||
Stream bitmapdata;
|
||||
|
||||
// Get resource from memory
|
||||
bitmapdata = General.ThisAssembly.GetManifestResourceStream("CodeImp.DoomBuilder.Resources." + Name);
|
||||
bitmap = (Bitmap)Image.FromStream(bitmapdata);
|
||||
|
||||
// Pass on to base
|
||||
base.LoadImage();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -102,14 +102,14 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
if(renderer.StartRendering(true))
|
||||
{
|
||||
// Render lines
|
||||
renderer.RenderLinedefSet(General.Map.Map, General.Map.Map.Linedefs);
|
||||
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
|
||||
|
||||
// Render highlighted item
|
||||
if(highlighted != null)
|
||||
renderer.RenderLinedef(highlighted, General.Colors.Highlight);
|
||||
|
||||
// Render vertices
|
||||
renderer.RenderVerticesSet(General.Map.Map, General.Map.Map.Vertices);
|
||||
renderer.RenderVerticesSet(General.Map.Map.Vertices);
|
||||
|
||||
// Done
|
||||
renderer.FinishRendering();
|
||||
|
|
|
@ -100,8 +100,8 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
if(renderer.StartRendering(true))
|
||||
{
|
||||
// Render stuff
|
||||
renderer.RenderLinedefSet(General.Map.Map, General.Map.Map.Linedefs);
|
||||
renderer.RenderVerticesSet(General.Map.Map, General.Map.Map.Vertices);
|
||||
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
|
||||
renderer.RenderVerticesSet(General.Map.Map.Vertices);
|
||||
|
||||
// Render highlighted item
|
||||
if(highlighted != null)
|
||||
|
|
|
@ -102,13 +102,16 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
if(renderer.StartRendering(true))
|
||||
{
|
||||
// Render stuff
|
||||
renderer.RenderLinedefSet(General.Map.Map, General.Map.Map.Linedefs);
|
||||
renderer.RenderVerticesSet(General.Map.Map, General.Map.Map.Vertices);
|
||||
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
|
||||
renderer.RenderVerticesSet(General.Map.Map.Vertices);
|
||||
|
||||
// Render highlighted item
|
||||
if(highlighted != null)
|
||||
renderer.RenderVertex(highlighted, General.Colors.Highlight);
|
||||
|
||||
// Render things
|
||||
renderer.RenderThingSet(General.Map.Map.Things);
|
||||
|
||||
// Done
|
||||
renderer.FinishRendering();
|
||||
}
|
||||
|
|
|
@ -73,7 +73,10 @@ namespace CodeImp.DoomBuilder.IO
|
|||
|
||||
// Read things
|
||||
ReadThings(map, firstindex);
|
||||
|
||||
|
||||
// Remove unused vertices
|
||||
map.RemoveUnusedVertices();
|
||||
|
||||
// Return result;
|
||||
return map;
|
||||
}
|
||||
|
|
|
@ -433,6 +433,21 @@ namespace CodeImp.DoomBuilder.Map
|
|||
// TODO: Make this
|
||||
}
|
||||
|
||||
// This removes unused vertices
|
||||
public void RemoveUnusedVertices()
|
||||
{
|
||||
LinkedListNode<Vertex> vn, vc;
|
||||
|
||||
// Go for all vertices
|
||||
vn = vertices.First;
|
||||
while(vn != null)
|
||||
{
|
||||
vc = vn;
|
||||
vn = vc.Next;
|
||||
if(vc.Value.Linedefs.Count == 0) vertices.Remove(vc);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,10 +88,6 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Create resources list
|
||||
resources = new List<ID3DResource>();
|
||||
|
||||
// Create renderers
|
||||
renderer2d = new Renderer2D(this);
|
||||
renderer3d = new Renderer3D(this);
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
@ -121,6 +117,9 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// This completes initialization after the device has started or has been reset
|
||||
private void SetupSettings()
|
||||
{
|
||||
int intvalue;
|
||||
float floatvalue;
|
||||
|
||||
// Setup renderstates
|
||||
device.SetRenderState(RenderState.AntialiasedLineEnable, false);
|
||||
device.SetRenderState(RenderState.Ambient, Color.White.ToArgb());
|
||||
|
@ -142,19 +141,25 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
device.SetRenderState(RenderState.Clipping, true);
|
||||
device.SetRenderState(RenderState.CullMode, Cull.None);
|
||||
|
||||
// Make LOD bias hack until SlimDX has a SetSamplerState overload that accepts a float
|
||||
floatvalue = -0.99f;
|
||||
unsafe { General.CopyMemory(&intvalue, &floatvalue, new UIntPtr(4)); }
|
||||
|
||||
// Sampler settings
|
||||
device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
|
||||
device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
|
||||
device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);
|
||||
|
||||
device.SetSamplerState(0, SamplerState.MipMapLodBias, intvalue);
|
||||
|
||||
// Texture addressing
|
||||
device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Wrap);
|
||||
device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Wrap);
|
||||
device.SetSamplerState(0, SamplerState.AddressW, TextureAddress.Wrap);
|
||||
|
||||
// First texture stage
|
||||
device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1);
|
||||
device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.Modulate);
|
||||
device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
|
||||
device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.TFactor);
|
||||
device.SetTextureStageState(0, TextureStage.ResultArg, TextureArgument.Current);
|
||||
device.SetTextureStageState(0, TextureStage.TexCoordIndex, 0);
|
||||
|
||||
|
@ -162,9 +167,10 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
device.SetTextureStageState(1, TextureStage.ColorOperation, TextureOperation.Disable);
|
||||
|
||||
// First alpha stage
|
||||
device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.SelectArg1);
|
||||
device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate);
|
||||
device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture);
|
||||
|
||||
device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.TFactor);
|
||||
|
||||
// No more further stages
|
||||
device.SetTextureStageState(1, TextureStage.AlphaOperation, TextureOperation.Disable);
|
||||
|
||||
|
@ -236,10 +242,10 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
// Add event to cancel resize event
|
||||
//device.DeviceResizing += new CancelEventHandler(CancelResize);
|
||||
|
||||
// Reset renderers
|
||||
renderer2d.Reset();
|
||||
renderer3d.Reset();
|
||||
|
||||
// Create renderers
|
||||
renderer2d = new Renderer2D(this);
|
||||
renderer3d = new Renderer3D(this);
|
||||
|
||||
// Initialize settings
|
||||
SetupSettings();
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
public struct FlatVertex
|
||||
{
|
||||
// Vertex format
|
||||
public static readonly int Stride = 7 * 4;
|
||||
public static readonly int Stride = 6 * 4;
|
||||
|
||||
// Members
|
||||
public float x;
|
||||
|
|
|
@ -32,6 +32,7 @@ using SlimDX.Direct3D9;
|
|||
using SlimDX;
|
||||
using CodeImp.DoomBuilder.Geometry;
|
||||
using System.Drawing.Imaging;
|
||||
using CodeImp.DoomBuilder.Data;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -43,17 +44,31 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
private const byte DOUBLESIDED_LINE_ALPHA = 130;
|
||||
private const float FSAA_BLEND_FACTOR = 0.6f;
|
||||
private const float THING_ARROW_SIZE = 15f;
|
||||
private const float THING_CIRCLE_SIZE = 10f;
|
||||
private const int THING_BUFFER_STEP = 100;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
// Rendering memory
|
||||
// Rendering memory for lines and vertices
|
||||
private Texture tex;
|
||||
private int width, height;
|
||||
private int pwidth, pheight;
|
||||
private Plotter plotter;
|
||||
|
||||
private FlatVertex[] screenverts = new FlatVertex[4];
|
||||
private LockedRect lockedrect;
|
||||
|
||||
// Buffers for rendering things
|
||||
private VertexBuffer thingsvertices;
|
||||
private PixelColor[] thingcolors;
|
||||
private int numthings;
|
||||
private int maxthings;
|
||||
|
||||
// Images
|
||||
private ResourceImage thingtexture;
|
||||
|
||||
// View settings (world coordinates)
|
||||
private float scale;
|
||||
private float scaleinv;
|
||||
|
@ -79,6 +94,12 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
public Renderer2D(D3DGraphics graphics) : base(graphics)
|
||||
{
|
||||
// Initialize
|
||||
thingtexture = new ResourceImage("Thing2D.png");
|
||||
thingtexture.LoadImage();
|
||||
thingtexture.CreateTexture();
|
||||
|
||||
// Create texture for rendering lines/vertices
|
||||
CreateTexture();
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
|
@ -93,6 +114,9 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Clean up
|
||||
if(tex != null) tex.Dispose();
|
||||
tex = null;
|
||||
if(thingsvertices != null) thingsvertices.Dispose();
|
||||
thingsvertices = null;
|
||||
thingtexture.Dispose();
|
||||
|
||||
// Done
|
||||
base.Dispose();
|
||||
|
@ -106,56 +130,61 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// This draws the image on screen
|
||||
public void Present()
|
||||
{
|
||||
FlatVertex[] verts = new FlatVertex[4];
|
||||
|
||||
// Start drawing
|
||||
if(graphics.StartRendering(General.Colors.Background.PixelColor.ToInt()))
|
||||
{
|
||||
// Left top
|
||||
verts[0].x = -0.5f;
|
||||
verts[0].y = -0.5f;
|
||||
verts[0].w = 1f;
|
||||
verts[0].u = 0f;
|
||||
verts[0].v = 0f;
|
||||
|
||||
// Right top
|
||||
verts[1].x = pwidth - 0.5f;
|
||||
verts[1].y = -0.5f;
|
||||
verts[1].w = 1f;
|
||||
verts[1].u = 1f;
|
||||
verts[1].v = 0f;
|
||||
|
||||
// Left bottom
|
||||
verts[2].x = -0.5f;
|
||||
verts[2].y = pheight - 0.5f;
|
||||
verts[2].w = 1f;
|
||||
verts[2].u = 0f;
|
||||
verts[2].v = 1f;
|
||||
|
||||
// Right bottom
|
||||
verts[3].x = pwidth - 0.5f;
|
||||
verts[3].y = pheight - 0.5f;
|
||||
verts[3].w = 1f;
|
||||
verts[3].u = 1f;
|
||||
verts[3].v = 1f;
|
||||
|
||||
// Set renderstates AND shader settings
|
||||
// Set renderstates
|
||||
graphics.Device.SetTexture(0, tex);
|
||||
graphics.Device.SetRenderState(RenderState.CullMode, Cull.None);
|
||||
graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, true);
|
||||
graphics.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
|
||||
graphics.Device.SetRenderState(RenderState.DestBlend, Blend.InvSourceAlpha);
|
||||
graphics.Device.SetRenderState(RenderState.TextureFactor, -1);
|
||||
graphics.Shaders.Base2D.Texture1 = tex;
|
||||
graphics.Shaders.Base2D.SetSettings(1f / pwidth, 1f / pheight, FSAA_BLEND_FACTOR);
|
||||
|
||||
// Draw
|
||||
// Draw the lines and vertices texture
|
||||
graphics.Shaders.Base2D.Begin();
|
||||
graphics.Shaders.Base2D.BeginPass(0);
|
||||
try { graphics.Device.DrawUserPrimitives<FlatVertex>(PrimitiveType.TriangleStrip, 0, 2, verts); }
|
||||
catch(Exception) { }
|
||||
try { graphics.Device.DrawUserPrimitives<FlatVertex>(PrimitiveType.TriangleStrip, 0, 2, screenverts); } catch(Exception) { }
|
||||
graphics.Shaders.Base2D.EndPass();
|
||||
graphics.Shaders.Base2D.End();
|
||||
|
||||
// Do we have things to render?
|
||||
if((numthings > 0) && (thingsvertices != null))
|
||||
{
|
||||
// Set renderstates
|
||||
graphics.Device.SetRenderState(RenderState.CullMode, Cull.None);
|
||||
graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, true);
|
||||
graphics.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
|
||||
graphics.Device.SetRenderState(RenderState.DestBlend, Blend.InvSourceAlpha);
|
||||
graphics.Device.SetTexture(0, thingtexture.Texture);
|
||||
graphics.Shaders.Things2D.Texture1 = thingtexture.Texture;
|
||||
|
||||
// Set the vertex buffer
|
||||
graphics.Device.SetStreamSource(0, thingsvertices, 0, FlatVertex.Stride);
|
||||
|
||||
// Go for all things
|
||||
for(int i = 0; i < numthings; i++)
|
||||
{
|
||||
// Set renderstates
|
||||
graphics.Device.SetRenderState(RenderState.TextureFactor, thingcolors[i].ToInt());
|
||||
graphics.Shaders.Things2D.SetColors(thingcolors[i]);
|
||||
|
||||
// Draw the thing circle
|
||||
graphics.Shaders.Things2D.Begin();
|
||||
graphics.Shaders.Things2D.BeginPass(0);
|
||||
try { graphics.Device.DrawPrimitives(PrimitiveType.TriangleStrip, i * 8, 2); } catch(Exception) { }
|
||||
graphics.Shaders.Things2D.EndPass();
|
||||
|
||||
// Draw the thing icon
|
||||
graphics.Shaders.Things2D.BeginPass(1);
|
||||
try { graphics.Device.DrawPrimitives(PrimitiveType.TriangleStrip, i * 8 + 4, 2); } catch(Exception) { }
|
||||
graphics.Shaders.Things2D.EndPass();
|
||||
graphics.Shaders.Things2D.End();
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
graphics.FinishRendering();
|
||||
}
|
||||
|
@ -168,6 +197,12 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Trash old texture
|
||||
if(tex != null) tex.Dispose();
|
||||
tex = null;
|
||||
|
||||
// Trash things buffer
|
||||
if(thingsvertices != null) thingsvertices.Dispose();
|
||||
thingsvertices = null;
|
||||
maxthings = 0;
|
||||
numthings = 0;
|
||||
}
|
||||
|
||||
// This is called resets when the device is reset
|
||||
|
@ -205,13 +240,34 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
sd = tex.GetLevelDescription(0);
|
||||
pwidth = sd.Width;
|
||||
pheight = sd.Height;
|
||||
|
||||
// Setup screen vertices
|
||||
screenverts[0].x = 0.5f;
|
||||
screenverts[0].y = 0.5f;
|
||||
screenverts[0].w = 1f;
|
||||
screenverts[0].u = 1f / pwidth;
|
||||
screenverts[0].v = 1f / pheight;
|
||||
screenverts[1].x = pwidth - 1.5f;
|
||||
screenverts[1].y = 0.5f;
|
||||
screenverts[1].w = 1f;
|
||||
screenverts[1].u = 1f - 1f / pwidth;
|
||||
screenverts[1].v = 1f / pheight;
|
||||
screenverts[2].x = 0.5f;
|
||||
screenverts[2].y = pheight - 1.5f;
|
||||
screenverts[2].w = 1f;
|
||||
screenverts[2].u = 1f / pwidth;
|
||||
screenverts[2].v = 1f - 1f / pheight;
|
||||
screenverts[3].x = pwidth - 1.5f;
|
||||
screenverts[3].y = pheight - 1.5f;
|
||||
screenverts[3].w = 1f;
|
||||
screenverts[3].u = 1f - 1f / pwidth;
|
||||
screenverts[3].v = 1f - 1f / pheight;
|
||||
}
|
||||
|
||||
// This begins a drawing session
|
||||
public unsafe bool StartRendering(bool cleardisplay)
|
||||
{
|
||||
LockFlags lockflags;
|
||||
LockedRect rect;
|
||||
|
||||
// Do we have a texture?
|
||||
if(tex != null)
|
||||
|
@ -221,12 +277,15 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
else lockflags = LockFlags.NoSystemLock;
|
||||
|
||||
// Lock memory
|
||||
rect = tex.LockRectangle(0, lockflags);
|
||||
lockedrect = tex.LockRectangle(0, lockflags);
|
||||
|
||||
// Create plotter
|
||||
plotter = new Plotter((PixelColor*)rect.Data.DataPointer.ToPointer(), rect.Pitch / sizeof(PixelColor), pheight, width, height);
|
||||
plotter = new Plotter((PixelColor*)lockedrect.Data.DataPointer.ToPointer(), lockedrect.Pitch / sizeof(PixelColor), pheight, width, height);
|
||||
if(cleardisplay) plotter.Clear();
|
||||
|
||||
// Reset things buffer when display is cleared
|
||||
if(cleardisplay) ReserveThingsMemory(0, false);
|
||||
|
||||
// Ready for rendering
|
||||
return true;
|
||||
}
|
||||
|
@ -242,7 +301,8 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
// Unlock memory
|
||||
tex.UnlockRectangle(0);
|
||||
|
||||
lockedrect.Data.Dispose();
|
||||
|
||||
// Present new image
|
||||
Present();
|
||||
}
|
||||
|
@ -287,8 +347,128 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
#endregion
|
||||
|
||||
#region ================== Things
|
||||
|
||||
// This ensures there is enough place in the things buffer
|
||||
private void ReserveThingsMemory(int newnumthings, bool preserve)
|
||||
{
|
||||
int newmaxthings;
|
||||
DataStream stream;
|
||||
FlatVertex[] verts = null;
|
||||
PixelColor[] oldcolors = null;
|
||||
|
||||
// Do we need to resize the buffer?
|
||||
if((newnumthings > maxthings) || !preserve)
|
||||
{
|
||||
// Calculate new size
|
||||
newmaxthings = newnumthings + THING_BUFFER_STEP;
|
||||
|
||||
// Read old things data if we want to keep it
|
||||
if(preserve && (thingsvertices != null) && (numthings > 0))
|
||||
{
|
||||
stream = thingsvertices.Lock(0, numthings * 8 * FlatVertex.Stride, LockFlags.ReadOnly);
|
||||
verts = stream.ReadRange<FlatVertex>(numthings * 8);
|
||||
thingsvertices.Unlock();
|
||||
stream.Dispose();
|
||||
thingsvertices.Dispose();
|
||||
oldcolors = thingcolors;
|
||||
}
|
||||
|
||||
// Create new buffer
|
||||
thingsvertices = new VertexBuffer(graphics.Device, newmaxthings * 8 * FlatVertex.Stride, Usage.Dynamic, VertexFormat.None, Pool.Default);
|
||||
thingcolors = new PixelColor[newmaxthings];
|
||||
maxthings = newmaxthings;
|
||||
|
||||
// Keep old things?
|
||||
if(preserve && (verts != null))
|
||||
{
|
||||
// Write old things into new buffer
|
||||
stream = thingsvertices.Lock(0, maxthings * 8 * FlatVertex.Stride, LockFlags.Discard);
|
||||
stream.WriteRange<FlatVertex>(verts);
|
||||
thingsvertices.Unlock();
|
||||
stream.Dispose();
|
||||
oldcolors.CopyTo(thingcolors, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Things were trashed
|
||||
numthings = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This makes vertices for a thing
|
||||
private void CreateThingVerts(Thing t, ref FlatVertex[] verts, int offset)
|
||||
{
|
||||
// Transform to screen coordinates
|
||||
Vector2D screenpos = ((Vector2D)t.Position).GetTransformed(translatex, translatey, scale, -scale);
|
||||
|
||||
// Setup fixed rect for circle
|
||||
verts[offset].x = screenpos.x - THING_CIRCLE_SIZE;
|
||||
verts[offset].y = screenpos.y - THING_CIRCLE_SIZE;
|
||||
verts[offset].w = 1f;
|
||||
verts[offset].u = 1f / 512f;
|
||||
verts[offset].v = 1f / 128f;
|
||||
offset++;
|
||||
verts[offset].x = screenpos.x + THING_CIRCLE_SIZE;
|
||||
verts[offset].y = screenpos.y - THING_CIRCLE_SIZE;
|
||||
verts[offset].w = 1f;
|
||||
verts[offset].u = 0.25f - 1f / 512f;
|
||||
verts[offset].v = 1f / 128f;
|
||||
offset++;
|
||||
verts[offset].x = screenpos.x - THING_CIRCLE_SIZE;
|
||||
verts[offset].y = screenpos.y + THING_CIRCLE_SIZE;
|
||||
verts[offset].w = 1f;
|
||||
verts[offset].u = 1f / 512f;
|
||||
verts[offset].v = 1f - 1f / 128f;
|
||||
offset++;
|
||||
verts[offset].x = screenpos.x + THING_CIRCLE_SIZE;
|
||||
verts[offset].y = screenpos.y + THING_CIRCLE_SIZE;
|
||||
verts[offset].w = 1f;
|
||||
verts[offset].u = 0.25f - 1f / 512f;
|
||||
verts[offset].v = 1f - 1f / 128f;
|
||||
offset++;
|
||||
|
||||
// Setup rotated rect for arrow
|
||||
verts[offset].x = screenpos.x + (float)Math.Sin(t.Angle - Angle2D.PI * 0.25f) * THING_ARROW_SIZE;
|
||||
verts[offset].y = screenpos.y + (float)Math.Cos(t.Angle - Angle2D.PI * 0.25f) * THING_ARROW_SIZE;
|
||||
verts[offset].w = 1f;
|
||||
verts[offset].u = 0.50f;
|
||||
verts[offset].v = 0f;
|
||||
offset++;
|
||||
verts[offset].x = screenpos.x + (float)Math.Sin(t.Angle + Angle2D.PI * 0.25f) * THING_ARROW_SIZE;
|
||||
verts[offset].y = screenpos.y + (float)Math.Cos(t.Angle + Angle2D.PI * 0.25f) * THING_ARROW_SIZE;
|
||||
verts[offset].w = 1f;
|
||||
verts[offset].u = 0.75f;
|
||||
verts[offset].v = 0f;
|
||||
offset++;
|
||||
verts[offset].x = screenpos.x + (float)Math.Sin(t.Angle - Angle2D.PI * 0.75f) * THING_ARROW_SIZE;
|
||||
verts[offset].y = screenpos.y + (float)Math.Cos(t.Angle - Angle2D.PI * 0.75f) * THING_ARROW_SIZE;
|
||||
verts[offset].w = 1f;
|
||||
verts[offset].u = 0.50f;
|
||||
verts[offset].v = 1f;
|
||||
offset++;
|
||||
verts[offset].x = screenpos.x + (float)Math.Sin(t.Angle + Angle2D.PI * 0.75f) * THING_ARROW_SIZE;
|
||||
verts[offset].y = screenpos.y + (float)Math.Cos(t.Angle + Angle2D.PI * 0.75f) * THING_ARROW_SIZE;
|
||||
verts[offset].w = 1f;
|
||||
verts[offset].u = 0.75f;
|
||||
verts[offset].v = 1f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Colors
|
||||
|
||||
// This returns the color for a thing
|
||||
public PixelColor DetermineThingColor(Thing t)
|
||||
{
|
||||
// Determine color
|
||||
if(t.Selected > 0) return General.Colors.Selection;
|
||||
else return PixelColor.FromColor(Color.Tomato);
|
||||
|
||||
// TODO: Check against game configuration or embed color into thing
|
||||
}
|
||||
|
||||
// This returns the color for a vertex
|
||||
public PixelColor DetermineVertexColor(Vertex v)
|
||||
{
|
||||
|
@ -323,6 +503,68 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
#region ================== Map Rendering
|
||||
|
||||
// This adds a thing in the things buffer for rendering
|
||||
public void RenderThing(Thing t, PixelColor c)
|
||||
{
|
||||
FlatVertex[] verts = new FlatVertex[8];
|
||||
DataStream stream;
|
||||
|
||||
// TODO: Check if the thing is actually on screen
|
||||
|
||||
// Make sure there is enough memory reserved
|
||||
ReserveThingsMemory(numthings + 1, true);
|
||||
|
||||
// Store the thing color
|
||||
thingcolors[numthings] = c;
|
||||
|
||||
// Store vertices in buffer
|
||||
stream = thingsvertices.Lock(numthings * 8 * FlatVertex.Stride, 8 * FlatVertex.Stride, LockFlags.NoSystemLock);
|
||||
CreateThingVerts(t, ref verts, 0);
|
||||
stream.WriteRange<FlatVertex>(verts);
|
||||
thingsvertices.Unlock();
|
||||
stream.Dispose();
|
||||
|
||||
// Thing added!
|
||||
numthings++;
|
||||
}
|
||||
|
||||
// This adds a thing in the things buffer for rendering
|
||||
public void RenderThingSet(ICollection<Thing> things)
|
||||
{
|
||||
FlatVertex[] verts = new FlatVertex[things.Count * 8];
|
||||
DataStream stream;
|
||||
int offset = 0;
|
||||
int added = 0;
|
||||
|
||||
// Make sure there is enough memory reserved
|
||||
ReserveThingsMemory(numthings + things.Count, true);
|
||||
|
||||
// Go for all things
|
||||
foreach(Thing t in things)
|
||||
{
|
||||
// TODO: Check if the thing is actually on screen
|
||||
|
||||
// Store the thing color
|
||||
thingcolors[numthings + offset] = DetermineThingColor(t);
|
||||
|
||||
// Create vertices
|
||||
CreateThingVerts(t, ref verts, offset * 8);
|
||||
|
||||
// Next
|
||||
added++;
|
||||
offset++;
|
||||
}
|
||||
|
||||
// Store vertices in buffer
|
||||
stream = thingsvertices.Lock(numthings * 8 * FlatVertex.Stride, things.Count * 8 * FlatVertex.Stride, LockFlags.NoSystemLock);
|
||||
stream.WriteRange<FlatVertex>(verts);
|
||||
thingsvertices.Unlock();
|
||||
stream.Dispose();
|
||||
|
||||
// Things added!
|
||||
numthings += added;
|
||||
}
|
||||
|
||||
// This renders the linedefs of a sector with special color
|
||||
public void RenderSector(Sector s, PixelColor c)
|
||||
{
|
||||
|
@ -374,7 +616,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
|
||||
// This renders a set of linedefs
|
||||
public void RenderLinedefSet(MapSet map, ICollection<Linedef> linedefs)
|
||||
public void RenderLinedefSet(ICollection<Linedef> linedefs)
|
||||
{
|
||||
// Go for all linedefs
|
||||
foreach(Linedef l in linedefs) RenderLinedef(l, DetermineLinedefColor(l));
|
||||
|
@ -391,7 +633,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
|
||||
// This renders a set of vertices
|
||||
public void RenderVerticesSet(MapSet map, ICollection<Vertex> vertices)
|
||||
public void RenderVerticesSet(ICollection<Vertex> vertices)
|
||||
{
|
||||
// Go for all vertices
|
||||
foreach(Vertex v in vertices) RenderVertex(v, DetermineVertexColor(v));
|
||||
|
|
|
@ -51,6 +51,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
// Shaders
|
||||
private Base2DShader base2dshader;
|
||||
private Things2DShader things2dshader;
|
||||
|
||||
// Disposing
|
||||
private bool isdisposed = false;
|
||||
|
@ -62,6 +63,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
public bool Enabled { get { return useshaders; } }
|
||||
public string ShaderTechnique { get { return shadertechnique; } }
|
||||
public Base2DShader Base2D { get { return base2dshader; } }
|
||||
public Things2DShader Things2D { get { return things2dshader; } }
|
||||
public bool IsDisposed { get { return isdisposed; } }
|
||||
|
||||
#endregion
|
||||
|
@ -80,6 +82,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
// Initialize effects
|
||||
base2dshader = new Base2DShader(this);
|
||||
things2dshader = new Things2DShader(this);
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
|
@ -93,6 +96,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
// Clean up
|
||||
base2dshader.Dispose();
|
||||
things2dshader.Dispose();
|
||||
|
||||
// Done
|
||||
isdisposed = true;
|
||||
|
|
112
Source/Rendering/Things2DShader.cs
Normal file
112
Source/Rendering/Things2DShader.cs
Normal file
|
@ -0,0 +1,112 @@
|
|||
|
||||
#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.Direct3D;
|
||||
using SlimDX.Direct3D9;
|
||||
using SlimDX;
|
||||
using CodeImp.DoomBuilder.Geometry;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Rendering
|
||||
{
|
||||
internal sealed class Things2DShader : D3DShader
|
||||
{
|
||||
#region ================== Variables
|
||||
|
||||
// Property handlers
|
||||
private EffectHandle texture1;
|
||||
private EffectHandle thingcolor;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public Texture Texture1 { set { if(manager.Enabled) effect.SetValue(texture1, value); } }
|
||||
|
||||
#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");
|
||||
thingcolor = effect.GetParameter(null, "thingcolor");
|
||||
}
|
||||
|
||||
// Initialize world vertex declaration
|
||||
VertexElement[] elements = new VertexElement[]
|
||||
{
|
||||
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 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);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
public override void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
if(!isdisposed)
|
||||
{
|
||||
// Clean up
|
||||
texture1.Dispose();
|
||||
thingcolor.Dispose();
|
||||
|
||||
// Done
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This sets the settings
|
||||
public void SetColors(PixelColor thing)
|
||||
{
|
||||
// Set settings
|
||||
if(manager.Enabled) effect.SetValue(thingcolor, ColorValue.FromColor(Color.FromArgb(thing.ToInt())));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
BIN
Source/Resources/Thing2D.png
Normal file
BIN
Source/Resources/Thing2D.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -42,7 +42,7 @@ float4 addcolor(float4 c1, float4 c2)
|
|||
}
|
||||
|
||||
// Pixel shader
|
||||
float4 ps20_main(PixelData pd) : COLOR
|
||||
float4 ps_main(PixelData pd) : COLOR
|
||||
{
|
||||
// Take this pixel's color
|
||||
float4 c = tex2D(texture1samp, pd.uv);
|
||||
|
@ -69,7 +69,7 @@ technique SM20
|
|||
pass p0
|
||||
{
|
||||
VertexShader = null;
|
||||
PixelShader = compile ps_2_0 ps20_main();
|
||||
PixelShader = compile ps_2_0 ps_main();
|
||||
CullMode = None;
|
||||
ZEnable = false;
|
||||
AlphaBlendEnable = true;
|
||||
|
|
71
Source/Resources/things2d.fx
Normal file
71
Source/Resources/things2d.fx
Normal file
|
@ -0,0 +1,71 @@
|
|||
// Things 2D rendering shader
|
||||
// Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
||||
|
||||
// Pixel input data
|
||||
struct PixelData
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
// Colors
|
||||
float4 thingcolor;
|
||||
|
||||
// Texture1 input
|
||||
texture texture1
|
||||
<
|
||||
string UIName = "Texture1";
|
||||
string ResourceType = "2D";
|
||||
>;
|
||||
|
||||
// Texture sampler settings
|
||||
sampler2D texture1samp = sampler_state
|
||||
{
|
||||
Texture = <texture1>;
|
||||
MagFilter = Linear;
|
||||
MinFilter = Linear;
|
||||
MipFilter = Linear;
|
||||
AddressU = Wrap;
|
||||
AddressV = Wrap;
|
||||
MipMapLodBias = -0.99f;
|
||||
};
|
||||
|
||||
// Pixel shader for colored circle
|
||||
float4 ps_circle(PixelData pd) : COLOR
|
||||
{
|
||||
float4 c = tex2D(texture1samp, pd.uv);
|
||||
float4 s = tex2D(texture1samp, pd.uv + float2(0.25f, 0.0f));
|
||||
return lerp(c * thingcolor, float4(s.rgb, c.a), s.a);
|
||||
}
|
||||
|
||||
// Pixel shader for icon
|
||||
float4 ps_icon(PixelData pd) : COLOR
|
||||
{
|
||||
return tex2D(texture1samp, pd.uv);
|
||||
}
|
||||
|
||||
// Technique for shader model 2.0
|
||||
technique SM20
|
||||
{
|
||||
pass p0
|
||||
{
|
||||
VertexShader = null;
|
||||
PixelShader = compile ps_2_0 ps_circle();
|
||||
CullMode = None;
|
||||
ZEnable = false;
|
||||
AlphaBlendEnable = true;
|
||||
SrcBlend = SrcAlpha;
|
||||
DestBlend = InvSrcAlpha;
|
||||
}
|
||||
|
||||
pass p1
|
||||
{
|
||||
VertexShader = null;
|
||||
PixelShader = compile ps_2_0 ps_icon();
|
||||
CullMode = None;
|
||||
ZEnable = false;
|
||||
AlphaBlendEnable = true;
|
||||
SrcBlend = SrcAlpha;
|
||||
DestBlend = InvSrcAlpha;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue