- added overlay rendertarget

- renamed some rendering methods
- added rectangle rendering method for overlay
This commit is contained in:
codeimp 2008-04-12 16:07:10 +00:00
parent 3d43205f2c
commit 535ecc54a2
20 changed files with 1042 additions and 436 deletions

View file

@ -317,16 +317,19 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Rendering\Color2DShader.cs" />
<Compile Include="Rendering\Display2DShader.cs" />
<Compile Include="Rendering\ColorCollection.cs" />
<Compile Include="Rendering\ColorSetting.cs" />
<Compile Include="Rendering\D3DDevice.cs" />
<Compile Include="Data\ImageData.cs" />
<Compile Include="Rendering\D3DShader.cs" />
<Compile Include="Rendering\FlatQuad.cs" />
<Compile Include="Rendering\FlatVertex.cs" />
<Compile Include="Rendering\ID3DResource.cs" />
<Compile Include="Rendering\IRenderer2D.cs" />
<Compile Include="Rendering\IRenderer3D.cs" />
<Compile Include="Rendering\RenderLayers.cs" />
<Compile Include="Rendering\VisualGeometry.cs" />
<Compile Include="Rendering\PixelColor.cs" />
<Compile Include="Rendering\PixelColorBlock.cs" />
@ -503,6 +506,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Resources\DB2.ico" />
<EmbeddedResource Include="Resources\color2d.fx" />
<None Include="Resources\Splash2_small.png" />
<None Include="Resources\Splash2_trans.png" />
</ItemGroup>

View file

@ -138,14 +138,14 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
*/
// Render lines and vertices
renderer.RenderLinedefSet(unselectedlines);
renderer.RenderLinedefSet(selectedlines);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(unselectedlines);
renderer.PlotLinedefSet(selectedlines);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
// Draw the dragged item highlighted
// This is important to know, because this item is used
// for snapping to the grid and snapping to nearest items
renderer.RenderVertex(dragitem, ColorCollection.HIGHLIGHT);
renderer.PlotVertex(dragitem, ColorCollection.HIGHLIGHT);
// Done
renderer.Finish();

View file

@ -129,10 +129,10 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render lines
if(renderer.StartPlotter(true))
{
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderLinedef(highlighted, General.Colors.Highlight);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedef(highlighted, General.Colors.Highlight);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
renderer.Finish();
}
@ -156,9 +156,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Undraw previous highlight
if((highlighted != null) && !highlighted.IsDisposed)
{
renderer.RenderLinedef(highlighted, renderer.DetermineLinedefColor(highlighted));
renderer.RenderVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.RenderVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
renderer.PlotLinedef(highlighted, renderer.DetermineLinedefColor(highlighted));
renderer.PlotVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.PlotVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
}
// Set new highlight
@ -167,9 +167,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render highlighted item
if((highlighted != null) && !highlighted.IsDisposed)
{
renderer.RenderLinedef(highlighted, General.Colors.Highlight);
renderer.RenderVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.RenderVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
renderer.PlotLinedef(highlighted, General.Colors.Highlight);
renderer.PlotVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.PlotVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
}
// Done
@ -189,11 +189,15 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
base.MouseMove(e);
// Find the nearest linedef within highlight range
Linedef l = General.Map.Map.NearestLinedefRange(mousemappos, LINEDEF_HIGHLIGHT_RANGE / renderer.Scale);
// Not holding any buttons?
if(e.Button == MouseButtons.None)
{
// Find the nearest linedef within highlight range
Linedef l = General.Map.Map.NearestLinedefRange(mousemappos, LINEDEF_HIGHLIGHT_RANGE / renderer.Scale);
// Highlight if not the same
if(l != highlighted) Highlight(l);
// Highlight if not the same
if(l != highlighted) Highlight(l);
}
}
// Mouse leaves
@ -223,9 +227,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(false))
{
// Redraw highlight to show selection
renderer.RenderLinedef(highlighted, renderer.DetermineLinedefColor(highlighted));
renderer.RenderVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.RenderVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
renderer.PlotLinedef(highlighted, renderer.DetermineLinedefColor(highlighted));
renderer.PlotVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.PlotVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
renderer.Finish();
renderer.Present();
}
@ -250,9 +254,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(false))
{
// Redraw highlight to show selection
renderer.RenderLinedef(highlighted, renderer.DetermineLinedefColor(highlighted));
renderer.RenderVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.RenderVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
renderer.PlotLinedef(highlighted, renderer.DetermineLinedefColor(highlighted));
renderer.PlotVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.PlotVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
renderer.Finish();
renderer.Present();
}
@ -274,9 +278,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(false))
{
// Render highlighted item
renderer.RenderLinedef(highlighted, General.Colors.Highlight);
renderer.RenderVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.RenderVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
renderer.PlotLinedef(highlighted, General.Colors.Highlight);
renderer.PlotVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.PlotVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
renderer.Finish();
renderer.Present();
}

View file

@ -144,14 +144,14 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
*/
// Render lines and vertices
renderer.RenderLinedefSet(unselectedlines);
renderer.RenderLinedefSet(selectedlines);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(unselectedlines);
renderer.PlotLinedefSet(selectedlines);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
// Draw the dragged item highlighted
// This is important to know, because this item is used
// for snapping to the grid and snapping to nearest items
renderer.RenderVertex(dragitem, ColorCollection.HIGHLIGHT);
renderer.PlotVertex(dragitem, ColorCollection.HIGHLIGHT);
// Done
renderer.Finish();

View file

@ -30,6 +30,7 @@ using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using System.Drawing;
#endregion
@ -143,10 +144,10 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render lines and vertices
if(renderer.StartPlotter(true))
{
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderSector(highlighted, General.Colors.Highlight);
renderer.PlotSector(highlighted, General.Colors.Highlight);
renderer.Finish();
}
@ -169,7 +170,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
// Undraw previous highlight
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderSector(highlighted);
renderer.PlotSector(highlighted);
/*
// Undraw highlighted things
@ -183,7 +184,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render highlighted item
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderSector(highlighted, General.Colors.Highlight);
renderer.PlotSector(highlighted, General.Colors.Highlight);
/*
// Render highlighted things
@ -209,37 +210,41 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
base.MouseMove(e);
// Find the nearest linedef within highlight range
Linedef l = General.Map.Map.NearestLinedef(mousemappos);
// Not holding any buttons?
if(e.Button == MouseButtons.None)
{
// Find the nearest linedef within highlight range
Linedef l = General.Map.Map.NearestLinedef(mousemappos);
// Check on which side of the linedef the mouse is
float side = l.SideOfLine(mousemappos);
if(side > 0)
{
// Is there a sidedef here?
if(l.Back != null)
// Check on which side of the linedef the mouse is
float side = l.SideOfLine(mousemappos);
if(side > 0)
{
// Highlight if not the same
if(l.Back.Sector != highlighted) Highlight(l.Back.Sector);
// Is there a sidedef here?
if(l.Back != null)
{
// Highlight if not the same
if(l.Back.Sector != highlighted) Highlight(l.Back.Sector);
}
else
{
// Highlight nothing
if(highlighted != null) Highlight(null);
}
}
else
{
// Highlight nothing
if(highlighted != null) Highlight(null);
}
}
else
{
// Is there a sidedef here?
if(l.Front != null)
{
// Highlight if not the same
if(l.Front.Sector != highlighted) Highlight(l.Front.Sector);
}
else
{
// Highlight nothing
if(highlighted != null) Highlight(null);
// Is there a sidedef here?
if(l.Front != null)
{
// Highlight if not the same
if(l.Front.Sector != highlighted) Highlight(l.Front.Sector);
}
else
{
// Highlight nothing
if(highlighted != null) Highlight(null);
}
}
}
}
@ -271,7 +276,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(false))
{
// Redraw highlight to show selection
renderer.RenderSector(highlighted);
renderer.PlotSector(highlighted);
renderer.Finish();
renderer.Present();
}
@ -297,7 +302,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(false))
{
// Redraw highlight to show selection
renderer.RenderSector(highlighted);
renderer.PlotSector(highlighted);
renderer.Finish();
renderer.Present();
}
@ -319,7 +324,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(false))
{
// Render highlighted item
renderer.RenderSector(highlighted, General.Colors.Highlight);
renderer.PlotSector(highlighted, General.Colors.Highlight);
renderer.Finish();
renderer.Present();
}

View file

@ -131,10 +131,10 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render lines and vertices
if(renderer.StartPlotter(true))
{
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderSector(highlighted, General.Colors.Highlight);
renderer.PlotSector(highlighted, General.Colors.Highlight);
renderer.Finish();
}
@ -156,14 +156,14 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
// Undraw previous highlight
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderSector(highlighted);
renderer.PlotSector(highlighted);
// Set new highlight
highlighted = s;
// Render highlighted item
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderSector(highlighted, General.Colors.Highlight);
renderer.PlotSector(highlighted, General.Colors.Highlight);
// Done
renderer.Finish();
@ -253,7 +253,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(false))
{
// Redraw highlight to show selection
renderer.RenderSector(highlighted);
renderer.PlotSector(highlighted);
renderer.Finish();
renderer.Present();
}
@ -301,15 +301,15 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(true))
{
// Render lines and vertices
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
// Go for all triangle vertices
for(int i = 0; i < triangles.Count; i += 3)
{
renderer.RenderLine(triangles[i + 0], triangles[i + 1], General.Colors.Selection);
renderer.RenderLine(triangles[i + 1], triangles[i + 2], General.Colors.Selection);
renderer.RenderLine(triangles[i + 2], triangles[i + 0], General.Colors.Selection);
renderer.PlotLine(triangles[i + 0], triangles[i + 1], General.Colors.Selection);
renderer.PlotLine(triangles[i + 1], triangles[i + 2], General.Colors.Selection);
renderer.PlotLine(triangles[i + 2], triangles[i + 0], General.Colors.Selection);
}
// Done
@ -333,15 +333,15 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(true))
{
// Render lines and vertices
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
// Go for all triangle vertices
for(int i = 0; i < triangles.Count; i += 3)
{
renderer.RenderLine(triangles[i + 0], triangles[i + 1], General.Colors.Selection);
renderer.RenderLine(triangles[i + 1], triangles[i + 2], General.Colors.Selection);
renderer.RenderLine(triangles[i + 2], triangles[i + 0], General.Colors.Selection);
renderer.PlotLine(triangles[i + 0], triangles[i + 1], General.Colors.Selection);
renderer.PlotLine(triangles[i + 1], triangles[i + 2], General.Colors.Selection);
renderer.PlotLine(triangles[i + 2], triangles[i + 0], General.Colors.Selection);
}
// Done
@ -365,11 +365,11 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(true))
{
// Render lines and vertices
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
// Show the point
renderer.RenderVertexAt(v, c);
renderer.PlotVertexAt(v, c);
// Done
renderer.Finish();
@ -394,11 +394,11 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(true))
{
// Render lines and vertices
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
// Show the line
renderer.RenderLine(v1, v2, c);
renderer.PlotLine(v1, v2, c);
// Done
renderer.Finish();
@ -425,20 +425,20 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(true))
{
// Render lines and vertices
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
// Go for all vertices in the polygon
v = p.First;
while(v != null)
{
// Show the line
if(v.Next != null) renderer.RenderLine(v.Value.Position, v.Next.Value.Position, c);
if(v.Next != null) renderer.PlotLine(v.Value.Position, v.Next.Value.Position, c);
v = v.Next;
}
// Show last line as well
renderer.RenderLine(p.Last.Value.Position, p.First.Value.Position, c);
renderer.PlotLine(p.Last.Value.Position, p.First.Value.Position, c);
// Done
renderer.Finish();
@ -461,31 +461,31 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(true))
{
// Render lines and vertices
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
// Go for all remaining vertices
prev = null; first = null;
foreach(EarClipVertex v in remains)
{
// Show the line
if(prev != null) renderer.RenderLine(v.Position, prev.Position, PixelColor.FromColor(Color.OrangeRed));
if(prev != null) renderer.PlotLine(v.Position, prev.Position, PixelColor.FromColor(Color.OrangeRed));
if(prev == null) first = v;
prev = v;
if(v.IsReflex)
renderer.RenderVertexAt(v.Position, ColorCollection.SELECTION);
renderer.PlotVertexAt(v.Position, ColorCollection.SELECTION);
else
renderer.RenderVertexAt(v.Position, ColorCollection.VERTICES);
renderer.PlotVertexAt(v.Position, ColorCollection.VERTICES);
}
if(first != null) renderer.RenderLine(first.Position, prev.Position, PixelColor.FromColor(Color.OrangeRed));
if(first != null) renderer.PlotLine(first.Position, prev.Position, PixelColor.FromColor(Color.OrangeRed));
if(found != null)
{
renderer.RenderLine(found[0].Position, found[1].Position, PixelColor.FromColor(Color.SkyBlue));
renderer.RenderLine(found[1].Position, found[2].Position, PixelColor.FromColor(Color.SkyBlue));
renderer.RenderLine(found[2].Position, found[0].Position, PixelColor.FromColor(Color.SkyBlue));
renderer.RenderVertexAt(found[1].Position, ColorCollection.ASSOCIATION);
renderer.PlotLine(found[0].Position, found[1].Position, PixelColor.FromColor(Color.SkyBlue));
renderer.PlotLine(found[1].Position, found[2].Position, PixelColor.FromColor(Color.SkyBlue));
renderer.PlotLine(found[2].Position, found[0].Position, PixelColor.FromColor(Color.SkyBlue));
renderer.PlotVertexAt(found[1].Position, ColorCollection.ASSOCIATION);
}
// Done
@ -498,24 +498,24 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(renderer.StartPlotter(true))
{
// Render lines and vertices
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
// Go for all remaining vertices
prev = null; first = null;
foreach(EarClipVertex v in remains)
{
// Show the line
if(prev != null) renderer.RenderLine(v.Position, prev.Position, PixelColor.FromColor(Color.OrangeRed));
if(prev != null) renderer.PlotLine(v.Position, prev.Position, PixelColor.FromColor(Color.OrangeRed));
if(prev == null) first = v;
prev = v;
if(v.IsReflex)
renderer.RenderVertexAt(v.Position, ColorCollection.SELECTION);
renderer.PlotVertexAt(v.Position, ColorCollection.SELECTION);
else
renderer.RenderVertexAt(v.Position, ColorCollection.VERTICES);
renderer.PlotVertexAt(v.Position, ColorCollection.VERTICES);
}
if(first != null) renderer.RenderLine(first.Position, prev.Position, PixelColor.FromColor(Color.OrangeRed));
if(first != null) renderer.PlotLine(first.Position, prev.Position, PixelColor.FromColor(Color.OrangeRed));
// Done
renderer.Finish();

View file

@ -133,8 +133,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render lines and vertices
if(renderer.StartPlotter(true))
{
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
if((highlighted != null) && !(highlighted is Thing)) DrawHighlight(true);
renderer.Finish();
}
@ -161,21 +161,21 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(highlighted is Vertex)
{
if((highlighted as Vertex).IsDisposed) return;
renderer.RenderVertex(highlighted as Vertex, ColorCollection.HIGHLIGHT);
renderer.PlotVertex(highlighted as Vertex, ColorCollection.HIGHLIGHT);
}
// Linedef
else if(highlighted is Linedef)
{
if((highlighted as Linedef).IsDisposed) return;
renderer.RenderLinedef((highlighted as Linedef), General.Colors.Highlight);
renderer.RenderVertex((highlighted as Linedef).Start, renderer.DetermineVertexColor((highlighted as Linedef).Start));
renderer.RenderVertex((highlighted as Linedef).End, renderer.DetermineVertexColor((highlighted as Linedef).End));
renderer.PlotLinedef((highlighted as Linedef), General.Colors.Highlight);
renderer.PlotVertex((highlighted as Linedef).Start, renderer.DetermineVertexColor((highlighted as Linedef).Start));
renderer.PlotVertex((highlighted as Linedef).End, renderer.DetermineVertexColor((highlighted as Linedef).End));
}
// Sector
else if(highlighted is Sector)
{
if((highlighted as Sector).IsDisposed) return;
renderer.RenderSector((highlighted as Sector), General.Colors.Highlight);
renderer.PlotSector((highlighted as Sector), General.Colors.Highlight);
}
// Thing
else if(highlighted is Thing)
@ -191,21 +191,21 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(highlighted is Vertex)
{
if((highlighted as Vertex).IsDisposed) return;
renderer.RenderVertex(highlighted as Vertex, renderer.DetermineVertexColor(highlighted as Vertex));
renderer.PlotVertex(highlighted as Vertex, renderer.DetermineVertexColor(highlighted as Vertex));
}
// Linedef
else if(highlighted is Linedef)
{
if((highlighted as Linedef).IsDisposed) return;
renderer.RenderLinedef((highlighted as Linedef), renderer.DetermineLinedefColor((highlighted as Linedef)));
renderer.RenderVertex((highlighted as Linedef).Start, renderer.DetermineVertexColor((highlighted as Linedef).Start));
renderer.RenderVertex((highlighted as Linedef).End, renderer.DetermineVertexColor((highlighted as Linedef).End));
renderer.PlotLinedef((highlighted as Linedef), renderer.DetermineLinedefColor((highlighted as Linedef)));
renderer.PlotVertex((highlighted as Linedef).Start, renderer.DetermineVertexColor((highlighted as Linedef).Start));
renderer.PlotVertex((highlighted as Linedef).End, renderer.DetermineVertexColor((highlighted as Linedef).End));
}
// Sector
else if(highlighted is Sector)
{
if((highlighted as Sector).IsDisposed) return;
renderer.RenderSector((highlighted as Sector));
renderer.PlotSector((highlighted as Sector));
}
// Thing
else if(highlighted is Thing)

View file

@ -214,8 +214,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render lines and vertices
if(renderer.StartPlotter(true))
{
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
renderer.Finish();
}
}

View file

@ -113,8 +113,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render lines and vertices
if(renderer.StartPlotter(true))
{
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderThing(highlighted, General.Colors.Highlight);
renderer.Finish();
@ -165,11 +165,15 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
base.MouseMove(e);
// Find the nearest vertex within highlight range
Thing t = General.Map.Map.NearestThingSquareRange(mousemappos, THING_HIGHLIGHT_RANGE / renderer.Scale);
// Not holding any buttons?
if(e.Button == MouseButtons.None)
{
// Find the nearest vertex within highlight range
Thing t = General.Map.Map.NearestThingSquareRange(mousemappos, THING_HIGHLIGHT_RANGE / renderer.Scale);
// Highlight if not the same
if(t != highlighted) Highlight(t);
// Highlight if not the same
if(t != highlighted) Highlight(t);
}
}
// Mouse leaves

View file

@ -135,14 +135,14 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
*/
// Render lines and vertices
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(unselectedverts);
renderer.RenderVerticesSet(selectedverts);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(unselectedverts);
renderer.PlotVerticesSet(selectedverts);
// Draw the dragged item highlighted
// This is important to know, because this item is used
// for snapping to the grid and snapping to nearest items
renderer.RenderVertex(dragitem, ColorCollection.HIGHLIGHT);
renderer.PlotVertex(dragitem, ColorCollection.HIGHLIGHT);
// Done
renderer.Finish();

View file

@ -129,10 +129,10 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render lines and vertices
if(renderer.StartPlotter(true))
{
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
renderer.RenderVerticesSet(General.Map.Map.Vertices);
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderVertex(highlighted, ColorCollection.HIGHLIGHT);
renderer.PlotVertex(highlighted, ColorCollection.HIGHLIGHT);
renderer.Finish();
}
@ -155,14 +155,14 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
// Undraw previous highlight
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderVertex(highlighted, renderer.DetermineVertexColor(highlighted));
renderer.PlotVertex(highlighted, renderer.DetermineVertexColor(highlighted));
// Set new highlight
highlighted = v;
// Render highlighted item
if((highlighted != null) && !highlighted.IsDisposed)
renderer.RenderVertex(highlighted, ColorCollection.HIGHLIGHT);
renderer.PlotVertex(highlighted, ColorCollection.HIGHLIGHT);
// Done
renderer.Finish();
@ -218,7 +218,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Redraw highlight to show selection
if(renderer.StartPlotter(false))
{
renderer.RenderVertex(highlighted, renderer.DetermineVertexColor(highlighted));
renderer.PlotVertex(highlighted, renderer.DetermineVertexColor(highlighted));
renderer.Finish();
renderer.Present();
}
@ -237,7 +237,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Render highlighted item
if(renderer.StartPlotter(false))
{
renderer.RenderVertex(highlighted, ColorCollection.HIGHLIGHT);
renderer.PlotVertex(highlighted, ColorCollection.HIGHLIGHT);
renderer.Finish();
renderer.Present();
}

View file

@ -23,6 +23,7 @@ using System.Globalization;
using System.Text;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing;
#endregion

View file

@ -0,0 +1,91 @@
#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 Color2DShader : D3DShader
{
#region ================== Variables
#endregion
#region ================== Properties
#endregion
#region ================== Constructor / Disposer
// Constructor
public Color2DShader(ShaderManager manager) : base(manager)
{
// Load effect from file
effect = LoadEffect("color2d.fx");
// Initialize world vertex declaration
VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
new VertexElement(0, 20, 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
// Done
base.Dispose();
}
}
#endregion
#region ================== Methods
#endregion
}
}

View file

@ -124,6 +124,7 @@ namespace CodeImp.DoomBuilder.Rendering
device.SetRenderState(RenderState.AntialiasedLineEnable, false);
device.SetRenderState(RenderState.Ambient, Color.White.ToArgb());
device.SetRenderState(RenderState.AmbientMaterialSource, ColorSource.Material);
device.SetRenderState(RenderState.ColorWriteEnable, ColorWriteEnable.Red | ColorWriteEnable.Green | ColorWriteEnable.Blue | ColorWriteEnable.Alpha);
device.SetRenderState(RenderState.ColorVertex, false);
device.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Color1);
device.SetRenderState(RenderState.FillMode, FillMode.Solid);

View file

@ -0,0 +1,253 @@
#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.Drawing;
using SlimDX.Direct3D;
using SlimDX.Direct3D9;
using SlimDX;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
// FlatQuad
internal class FlatQuad
{
#region ================== Variables
// Vertices
private FlatVertex[] vertices;
private PrimitiveType type;
private int numvertices;
#endregion
#region ================== Properties
public FlatVertex[] Vertices { get { return vertices; } }
public PrimitiveType Type { get { return type; } }
#endregion
#region ================== Constructors
// Constructor
public FlatQuad(PrimitiveType type, float left, float top, float right, float bottom)
{
// Initialize
Initialize(type);
// Set coordinates
if(type == PrimitiveType.TriangleList)
SetTriangleListCoordinates(left, top, right, bottom, 0f, 0f, 1f, 1f);
else if(type == PrimitiveType.TriangleStrip)
SetTriangleStripCoordinates(left, top, right, bottom, 0f, 0f, 1f, 1f);
// We have no destructor
GC.SuppressFinalize(this);
}
// Constructor
public FlatQuad(PrimitiveType type, float left, float top, float right, float bottom, float twidth, float theight)
{
float twd, thd;
// Initialize
Initialize(type);
// Determine texture size dividers
twd = 1f / twidth;
thd = 1f / theight;
// Set coordinates
if(type == PrimitiveType.TriangleList)
SetTriangleListCoordinates(left, top, right, bottom, twd, thd, 1f - twd, 1f - thd);
else if(type == PrimitiveType.TriangleStrip)
SetTriangleStripCoordinates(left, top, right, bottom, twd, thd, 1f - twd, 1f - thd);
// We have no destructor
GC.SuppressFinalize(this);
}
// Constructor
public FlatQuad(PrimitiveType type, RectangleF pos, float tl, float tt, float tr, float tb)
{
// Initialize
Initialize(type);
// Set coordinates
if(type == PrimitiveType.TriangleList)
SetTriangleListCoordinates(pos.Left, pos.Top, pos.Right, pos.Bottom, tl, tt, tr, tb);
else if(type == PrimitiveType.TriangleStrip)
SetTriangleStripCoordinates(pos.Left, pos.Top, pos.Right, pos.Bottom, tl, tt, tr, tb);
// We have no destructor
GC.SuppressFinalize(this);
}
// Constructor
public FlatQuad(PrimitiveType type, float left, float top, float right, float bottom, float tl, float tt, float tr, float tb)
{
// Initialize
Initialize(type);
// Set coordinates
if(type == PrimitiveType.TriangleList)
SetTriangleListCoordinates(left, top, right, bottom, tl, tt, tr, tb);
else if(type == PrimitiveType.TriangleStrip)
SetTriangleStripCoordinates(left, top, right, bottom, tl, tt, tr, tb);
// We have no destructor
GC.SuppressFinalize(this);
}
#endregion
#region ================== Methods
// This sets the color on all vertices
public void SetColors(int color)
{
// Go for all vertices to set the color
for(int i = 0; i < numvertices; i++)
vertices[i].c = color;
}
// This sets the color on all vertices
public void SetColors(int clt, int crt, int clb, int crb)
{
// Determine polygon type
if(type == PrimitiveType.TriangleList)
{
// Go for all vertices to set the color
vertices[0].c = clt;
vertices[1].c = crt;
vertices[2].c = clb;
vertices[3].c = clb;
vertices[4].c = crt;
vertices[5].c = crb;
}
else if(type == PrimitiveType.TriangleStrip)
{
// Go for all vertices to set the color
vertices[0].c = clt;
vertices[1].c = crt;
vertices[2].c = clb;
vertices[3].c = crb;
}
}
// This applies coordinates for TriangleList type
private void SetTriangleListCoordinates(float vl, float vt, float vr, float vb,
float tl, float tt, float tr, float tb)
{
// Setup coordinates
vertices[0].x = vl;
vertices[0].y = vt;
vertices[1].x = vr;
vertices[1].y = vt;
vertices[2].x = vl;
vertices[2].y = vb;
vertices[3].x = vl;
vertices[3].y = vb;
vertices[4].x = vr;
vertices[4].y = vt;
vertices[5].x = vr;
vertices[5].y = vb;
// Set texture coordinates
vertices[0].u = tl;
vertices[0].v = tt;
vertices[1].u = tr;
vertices[1].v = tt;
vertices[2].u = tl;
vertices[2].v = tb;
vertices[3].u = tl;
vertices[3].v = tb;
vertices[4].u = tr;
vertices[4].v = tt;
vertices[5].u = tr;
vertices[5].v = tb;
}
// This applies coordinates for TriangleStrip type
private void SetTriangleStripCoordinates(float vl, float vt, float vr, float vb,
float tl, float tt, float tr, float tb)
{
// Setup coordinates
vertices[0].x = vl;
vertices[0].y = vt;
vertices[1].x = vr;
vertices[1].y = vt;
vertices[2].x = vl;
vertices[2].y = vb;
vertices[3].x = vr;
vertices[3].y = vb;
// Set texture coordinates
vertices[0].u = tl;
vertices[0].v = tt;
vertices[1].u = tr;
vertices[1].v = tt;
vertices[2].u = tl;
vertices[2].v = tb;
vertices[3].u = tr;
vertices[3].v = tb;
}
// This initializes vertices to default values
private void Initialize(PrimitiveType type)
{
// Determine primitive type
this.type = type;
// Determine number of vertices
if(type == PrimitiveType.TriangleList)
numvertices = 6;
else if(type == PrimitiveType.TriangleStrip)
numvertices = 4;
else
throw new NotSupportedException("Unsupported PrimitiveType");
// Make the array
vertices = new FlatVertex[numvertices];
// Go for all vertices
for(int i = 0; i < numvertices; i++)
{
// Initialize to defaults
vertices[i].w = 1f;
vertices[i].c = -1;
}
}
#endregion
#region ================== Rendering
// This renders the quad
public void Render(D3DDevice device)
{
// Render the quad
device.Device.DrawUserPrimitives<FlatVertex>(type, 0, 2, vertices);
}
#endregion
}
}

View file

@ -54,20 +54,22 @@ namespace CodeImp.DoomBuilder.Rendering
// Rendering management methods
bool StartPlotter(bool clear);
bool StartThings(bool clear);
bool StartOverlay(bool clear);
void Finish();
void SetThingsRenderOrder(bool front);
void Present();
// Drawing methods
void RenderLine(Vector2D start, Vector2D end, PixelColor c);
void RenderLinedef(Linedef l, PixelColor c);
void RenderLinedefSet(ICollection<Linedef> linedefs);
void RenderSector(Sector s);
void RenderSector(Sector s, PixelColor c);
void PlotLine(Vector2D start, Vector2D end, PixelColor c);
void PlotLinedef(Linedef l, PixelColor c);
void PlotLinedefSet(ICollection<Linedef> linedefs);
void PlotSector(Sector s);
void PlotSector(Sector s, PixelColor c);
void PlotVertex(Vertex v, int colorindex);
void PlotVertexAt(Vector2D v, int colorindex);
void PlotVerticesSet(ICollection<Vertex> vertices);
void RenderThing(Thing t, PixelColor c);
void RenderThingSet(ICollection<Thing> things);
void RenderVertex(Vertex v, int colorindex);
void RenderVertexAt(Vector2D v, int colorindex);
void RenderVerticesSet(ICollection<Vertex> vertices);
void RenderRectangle(RectangleF rect, float bordersize, PixelColor c, bool transformrect);
}
}

View file

@ -0,0 +1,21 @@
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
internal enum RenderLayers : int
{
None = 0,
Background = 1,
Plotter = 2,
Things = 3,
Overlay = 4
}
}

View file

@ -43,17 +43,18 @@ namespace CodeImp.DoomBuilder.Rendering
/* This renders a 2D presentation of the map
* This is done in several layers:
*
* 1) Background image
* 1) Background grid
*
* 2) Things
*
* 3) Plotter (grid and geometric structures)
* 3) Plotter (geometric structures)
*
* 4) Overlay
*
* The order of layers 2 and 3 can be changed by
* calling SetThingsRenderOrder.
*/
internal unsafe sealed class Renderer2D : Renderer, IRenderer2D
{
#region ================== Constants
@ -75,15 +76,17 @@ namespace CodeImp.DoomBuilder.Rendering
private Texture backtex;
private Texture plottertex;
private Texture thingstex;
private Texture overlaytex;
// Locking data
private LockedRect plotlocked;
private Surface thingssurface;
private Surface targetsurface;
// Rendertarget sizes
private Size windowsize;
private Size structsize;
private Size thingssize;
private Size overlaysize;
private Size backsize;
// Geometry plotter
@ -100,6 +103,7 @@ namespace CodeImp.DoomBuilder.Rendering
// Render settings
private bool thingsfront;
private int vertexsize;
private RenderLayers renderlayer = RenderLayers.None;
// Images
private ResourceImage thingtexture;
@ -237,6 +241,21 @@ namespace CodeImp.DoomBuilder.Rendering
// Render things in front?
if(thingsfront) PresentThings(1f);
// Set renderstates
graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, true);
graphics.Device.SetRenderState(RenderState.AlphaTestEnable, false);
graphics.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
graphics.Device.SetRenderState(RenderState.DestBlend, Blend.InvSourceAlpha);
graphics.Device.SetRenderState(RenderState.TextureFactor, (new ColorValue(1f, 1f, 1f, 1f)).ToArgb());
graphics.Device.SetTexture(0, overlaytex);
graphics.Shaders.Display2D.Texture1 = overlaytex;
graphics.Shaders.Display2D.SetSettings(1f / thingssize.Width, 1f / thingssize.Height, FSAA_BLEND_FACTOR, 1f);
// Draw the overlay texture
graphics.Shaders.Display2D.BeginPass(0);
graphics.Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
graphics.Shaders.Display2D.EndPass();
// Done
graphics.Shaders.Display2D.End();
graphics.FinishRendering();
@ -307,12 +326,14 @@ namespace CodeImp.DoomBuilder.Rendering
// Trash rendertargets
if(plottertex != null) plottertex.Dispose();
if(thingstex != null) thingstex.Dispose();
if(overlaytex != null) overlaytex.Dispose();
if(backtex != null) backtex.Dispose();
if(screenverts != null) screenverts.Dispose();
plottertex = null;
thingstex = null;
backtex = null;
screenverts = null;
overlaytex = null;
// Trash things batch buffer
if(thingsvertices != null) thingsvertices.Dispose();
@ -340,6 +361,7 @@ namespace CodeImp.DoomBuilder.Rendering
plottertex = new Texture(graphics.Device, windowsize.Width, windowsize.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
thingstex = new Texture(graphics.Device, windowsize.Width, windowsize.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
backtex = new Texture(graphics.Device, windowsize.Width, windowsize.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
overlaytex = new Texture(graphics.Device, windowsize.Width, windowsize.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
// Get the real surface sizes
sd = plottertex.GetLevelDescription(0);
@ -351,7 +373,15 @@ namespace CodeImp.DoomBuilder.Rendering
sd = backtex.GetLevelDescription(0);
backsize.Width = sd.Width;
backsize.Height = sd.Height;
sd = overlaytex.GetLevelDescription(0);
overlaysize.Width = sd.Width;
overlaysize.Height = sd.Height;
// Clear rendertargets
StartPlotter(true); Finish();
StartThings(true); Finish();
StartOverlay(true); Finish();
// Create vertex buffers
screenverts = new VertexBuffer(graphics.Device, 4 * sizeof(FlatVertex), Usage.Dynamic | Usage.WriteOnly, VertexFormat.None, Pool.Default);
@ -441,6 +471,307 @@ namespace CodeImp.DoomBuilder.Rendering
#endregion
#region ================== Colors
// This returns the color for a thing
public PixelColor DetermineThingColor(Thing t)
{
// Determine color
if(t.Selected) return General.Colors.Selection;
else return t.Color;
}
// This returns the color for a vertex
public int DetermineVertexColor(Vertex v)
{
// Determine color
if(v.Selected) return ColorCollection.SELECTION;
else return ColorCollection.VERTICES;
}
// This returns the color for a linedef
public PixelColor DetermineLinedefColor(Linedef l)
{
// Impassable lines
if((l.Flags & General.Map.Config.ImpassableFlags) != 0)
{
// Determine color
if(l.Selected) return General.Colors.Selection;
else if(l.Action != 0) return General.Colors.Actions;
else return General.Colors.Linedefs;
}
else
{
// Determine color
if(l.Selected) return General.Colors.Selection;
else if(l.Action != 0) return General.Colors.Actions.WithAlpha(DOUBLESIDED_LINE_ALPHA);
else if((l.Flags & General.Map.Config.SoundLinedefFlags) != 0) return General.Colors.Sounds.WithAlpha(DOUBLESIDED_LINE_ALPHA);
else return General.Colors.Linedefs.WithAlpha(DOUBLESIDED_LINE_ALPHA);
}
}
#endregion
#region ================== Settings
// This sets the things in front or back
public void SetThingsRenderOrder(bool front)
{
// Set things render order
this.thingsfront = front;
}
#endregion
#region ================== Start / Finish
// This begins a drawing session
public unsafe bool StartPlotter(bool clear)
{
if(renderlayer != RenderLayers.None) throw new InvalidCallException("Renderer starting called before finished previous layer. Call Finish() first!");
renderlayer = RenderLayers.Plotter;
// Rendertargets available?
if(plottertex != null)
{
// Lock structures rendertarget memory
plotlocked = plottertex.LockRectangle(0, LockFlags.NoSystemLock);
// Create structures plotter
plotter = new Plotter((PixelColor*)plotlocked.Data.DataPointer.ToPointer(), plotlocked.Pitch / sizeof(PixelColor), structsize.Height, structsize.Width, structsize.Height);
if(clear) plotter.Clear();
// Redraw grid when structures image was cleared
if(clear)
{
RenderBackgroundGrid();
SetupBackground();
}
// Ready for rendering
return true;
}
else
{
// Can't render!
Finish();
return false;
}
}
// This begins a drawing session
public unsafe bool StartThings(bool clear)
{
if(renderlayer != RenderLayers.None) throw new InvalidCallException("Renderer starting called before finished previous layer. Call Finish() first!");
renderlayer = RenderLayers.Things;
// Rendertargets available?
if(thingstex != null)
{
// Always trash things batch buffer
if(thingsvertices != null) thingsvertices.Dispose();
thingsvertices = null;
numthings = 0;
maxthings = 0;
// Set the rendertarget to the things texture
targetsurface = thingstex.GetSurfaceLevel(0);
if(graphics.StartRendering(clear, 0, targetsurface, null))
{
// Ready for rendering
return true;
}
else
{
// Can't render!
Finish();
return false;
}
}
else
{
// Can't render!
Finish();
return false;
}
}
// This begins a drawing session
public unsafe bool StartOverlay(bool clear)
{
if(renderlayer != RenderLayers.None) throw new InvalidCallException("Renderer starting called before finished previous layer. Call Finish() first!");
renderlayer = RenderLayers.Overlay;
// Rendertargets available?
if(overlaytex != null)
{
// Set the rendertarget to the things texture
targetsurface = overlaytex.GetSurfaceLevel(0);
if(graphics.StartRendering(clear, 0, targetsurface, null))
{
// Ready for rendering
return true;
}
else
{
// Can't render!
Finish();
return false;
}
}
else
{
// Can't render!
Finish();
return false;
}
}
// This ends a drawing session
public void Finish()
{
// Stop rendering
graphics.FinishRendering();
// Clean up plotter
if(renderlayer == RenderLayers.Plotter)
{
if(plottertex != null) plottertex.UnlockRectangle(0);
if(plotlocked.Data != null) plotlocked.Data.Dispose();
plotter = null;
}
// Clean up things / overlay
if((renderlayer == RenderLayers.Things) || (renderlayer == RenderLayers.Overlay))
{
// Release rendertarget
try
{
graphics.Device.SetDepthStencilSurface(graphics.DepthBuffer);
graphics.Device.SetRenderTarget(0, graphics.BackBuffer);
}
catch(Exception) { }
if(targetsurface != null) targetsurface.Dispose();
targetsurface = null;
}
// Done
renderlayer = RenderLayers.None;
}
#endregion
#region ================== Background
// This sets up background image vertices
private void SetupBackground()
{
Vector2D ltpos, rbpos;
Vector2D backoffset = new Vector2D((float)General.Map.Grid.BackgroundX, (float)General.Map.Grid.BackgroundY);
Vector2D backimagesize = new Vector2D((float)General.Map.Grid.Background.Width, (float)General.Map.Grid.Background.Height);
// Only if a background image is set
if((General.Map.Grid.Background != null) &&
!(General.Map.Grid.Background is NullImage))
{
// Make vertices
backimageverts = CreateScreenVerts(windowsize);
// Determine map coordinates for view window
ltpos = GetMapCoordinates(new Vector2D(0f, 0f));
rbpos = GetMapCoordinates(new Vector2D(windowsize.Width, windowsize.Height));
// Offset by given background offset
ltpos -= backoffset;
rbpos -= backoffset;
// Calculate UV coordinates
// NOTE: backimagesize.y is made negative to match Doom's coordinate system
backimageverts[0].u = ltpos.x / backimagesize.x;
backimageverts[0].v = ltpos.y / -backimagesize.y;
backimageverts[1].u = rbpos.x / backimagesize.x;
backimageverts[1].v = ltpos.y / -backimagesize.y;
backimageverts[2].u = ltpos.x / backimagesize.x;
backimageverts[2].v = rbpos.y / -backimagesize.y;
backimageverts[3].u = rbpos.x / backimagesize.x;
backimageverts[3].v = rbpos.y / -backimagesize.y;
}
else
{
// No background image
backimageverts = null;
}
}
// This renders all grid
private void RenderBackgroundGrid()
{
Plotter gridplotter;
LockedRect lockedrect;
// Do we need to redraw grid?
if((lastgridscale != scale) || (lastgridx != offsetx) || (lastgridy != offsety))
{
// Lock background rendertarget memory
lockedrect = backtex.LockRectangle(0, LockFlags.NoSystemLock);
// Create a plotter
gridplotter = new Plotter((PixelColor*)lockedrect.Data.DataPointer.ToPointer(), lockedrect.Pitch / sizeof(PixelColor), backsize.Height, backsize.Width, backsize.Height);
gridplotter.Clear();
// Render normal grid
RenderGrid(General.Map.Grid.GridSize, General.Colors.Grid, gridplotter);
// Render 64 grid
if(General.Map.Grid.GridSize <= 64) RenderGrid(64f, General.Colors.Grid64, gridplotter);
// Done
backtex.UnlockRectangle(0);
lockedrect.Data.Dispose();
lastgridscale = scale;
lastgridx = offsetx;
lastgridy = offsety;
}
}
// This renders the grid
private void RenderGrid(float size, PixelColor c, Plotter gridplotter)
{
Vector2D ltpos, rbpos;
Vector2D pos = new Vector2D();
float sizeinv = 1f / size;
// Only render grid when not screen-filling
if((size * scale) > 6f)
{
// Determine map coordinates for view window
ltpos = GetMapCoordinates(new Vector2D(0, 0));
rbpos = GetMapCoordinates(new Vector2D(windowsize.Width, windowsize.Height));
// Clip to nearest grid
ltpos = GridSetup.SnappedToGrid(ltpos, size, sizeinv);
rbpos = GridSetup.SnappedToGrid(rbpos, size, sizeinv);
// Draw all horizontal grid lines
for(float y = ltpos.y + size; y > rbpos.y - size; y -= size)
{
pos.y = y;
pos = pos.GetTransformed(translatex, translatey, scale, -scale);
gridplotter.DrawGridLineH((int)pos.y, c);
}
// Draw all vertical grid lines
for(float x = ltpos.x - size; x < rbpos.x + size; x += size)
{
pos.x = x;
pos = pos.GetTransformed(translatex, translatey, scale, -scale);
gridplotter.DrawGridLineV((int)pos.x, c);
}
}
}
#endregion
#region ================== Things
// This ensures there is enough place in the things buffer
@ -631,274 +962,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.Shaders.Things2D.End();
}
}
#endregion
#region ================== Colors
// This returns the color for a thing
public PixelColor DetermineThingColor(Thing t)
{
// Determine color
if(t.Selected) return General.Colors.Selection;
else return t.Color;
}
// This returns the color for a vertex
public int DetermineVertexColor(Vertex v)
{
// Determine color
if(v.Selected) return ColorCollection.SELECTION;
else return ColorCollection.VERTICES;
}
// This returns the color for a linedef
public PixelColor DetermineLinedefColor(Linedef l)
{
// Impassable lines
if((l.Flags & General.Map.Config.ImpassableFlags) != 0)
{
// Determine color
if(l.Selected) return General.Colors.Selection;
else if(l.Action != 0) return General.Colors.Actions;
else return General.Colors.Linedefs;
}
else
{
// Determine color
if(l.Selected) return General.Colors.Selection;
else if(l.Action != 0) return General.Colors.Actions.WithAlpha(DOUBLESIDED_LINE_ALPHA);
else if((l.Flags & General.Map.Config.SoundLinedefFlags) != 0) return General.Colors.Sounds.WithAlpha(DOUBLESIDED_LINE_ALPHA);
else return General.Colors.Linedefs.WithAlpha(DOUBLESIDED_LINE_ALPHA);
}
}
#endregion
#region ================== Settings
// This sets the things in front or back
public void SetThingsRenderOrder(bool front)
{
// Set things render order
this.thingsfront = front;
}
#endregion
#region ================== Background
// This sets up background image vertices
private void SetupBackground()
{
Vector2D ltpos, rbpos;
Vector2D backoffset = new Vector2D((float)General.Map.Grid.BackgroundX, (float)General.Map.Grid.BackgroundY);
Vector2D backimagesize = new Vector2D((float)General.Map.Grid.Background.Width, (float)General.Map.Grid.Background.Height);
// Only if a background image is set
if((General.Map.Grid.Background != null) &&
!(General.Map.Grid.Background is NullImage))
{
// Make vertices
backimageverts = CreateScreenVerts(windowsize);
// Determine map coordinates for view window
ltpos = GetMapCoordinates(new Vector2D(0f, 0f));
rbpos = GetMapCoordinates(new Vector2D(windowsize.Width, windowsize.Height));
// Offset by given background offset
ltpos -= backoffset;
rbpos -= backoffset;
// Calculate UV coordinates
// NOTE: backimagesize.y is made negative to match Doom's coordinate system
backimageverts[0].u = ltpos.x / backimagesize.x;
backimageverts[0].v = ltpos.y / -backimagesize.y;
backimageverts[1].u = rbpos.x / backimagesize.x;
backimageverts[1].v = ltpos.y / -backimagesize.y;
backimageverts[2].u = ltpos.x / backimagesize.x;
backimageverts[2].v = rbpos.y / -backimagesize.y;
backimageverts[3].u = rbpos.x / backimagesize.x;
backimageverts[3].v = rbpos.y / -backimagesize.y;
}
else
{
// No background image
backimageverts = null;
}
}
// This renders all grid
private void RenderBackgroundGrid()
{
Plotter gridplotter;
LockedRect lockedrect;
// Do we need to redraw grid?
if((lastgridscale != scale) || (lastgridx != offsetx) || (lastgridy != offsety))
{
// Lock background rendertarget memory
lockedrect = backtex.LockRectangle(0, LockFlags.NoSystemLock);
// Create a plotter
gridplotter = new Plotter((PixelColor*)lockedrect.Data.DataPointer.ToPointer(), lockedrect.Pitch / sizeof(PixelColor), backsize.Height, backsize.Width, backsize.Height);
gridplotter.Clear();
// Render normal grid
RenderGrid(General.Map.Grid.GridSize, General.Colors.Grid, gridplotter);
// Render 64 grid
if(General.Map.Grid.GridSize <= 64) RenderGrid(64f, General.Colors.Grid64, gridplotter);
// Done
backtex.UnlockRectangle(0);
lockedrect.Data.Dispose();
lastgridscale = scale;
lastgridx = offsetx;
lastgridy = offsety;
}
}
// This renders the grid
private void RenderGrid(float size, PixelColor c, Plotter gridplotter)
{
Vector2D ltpos, rbpos;
Vector2D pos = new Vector2D();
float sizeinv = 1f / size;
// Only render grid when not screen-filling
if((size * scale) > 6f)
{
// Determine map coordinates for view window
ltpos = GetMapCoordinates(new Vector2D(0, 0));
rbpos = GetMapCoordinates(new Vector2D(windowsize.Width, windowsize.Height));
// Clip to nearest grid
ltpos = GridSetup.SnappedToGrid(ltpos, size, sizeinv);
rbpos = GridSetup.SnappedToGrid(rbpos, size, sizeinv);
// Draw all horizontal grid lines
for(float y = ltpos.y + size; y > rbpos.y - size; y -= size)
{
pos.y = y;
pos = pos.GetTransformed(translatex, translatey, scale, -scale);
gridplotter.DrawGridLineH((int)pos.y, c);
}
// Draw all vertical grid lines
for(float x = ltpos.x - size; x < rbpos.x + size; x += size)
{
pos.x = x;
pos = pos.GetTransformed(translatex, translatey, scale, -scale);
gridplotter.DrawGridLineV((int)pos.x, c);
}
}
}
#endregion
#region ================== Basic Tools
#endregion
#region ================== Rendering
// This begins a drawing session
public unsafe bool StartPlotter(bool clear)
{
// Rendertargets available?
if(plottertex != null)
{
// Lock structures rendertarget memory
plotlocked = plottertex.LockRectangle(0, LockFlags.NoSystemLock);
// Create structures plotter
plotter = new Plotter((PixelColor*)plotlocked.Data.DataPointer.ToPointer(), plotlocked.Pitch / sizeof(PixelColor), structsize.Height, structsize.Width, structsize.Height);
if(clear) plotter.Clear();
// Redraw grid when structures image was cleared
if(clear) RenderBackgroundGrid();
// Always trash things batch buffer
if(thingsvertices != null) thingsvertices.Dispose();
thingsvertices = null;
numthings = 0;
maxthings = 0;
// Setup vertices for background image
SetupBackground();
// Ready for rendering
return true;
}
else
{
// Can't render!
Finish();
return false;
}
}
// This begins a drawing session
public unsafe bool StartThings(bool clear)
{
// Rendertargets available?
if(thingstex != null)
{
// Always trash things batch buffer
if(thingsvertices != null) thingsvertices.Dispose();
thingsvertices = null;
numthings = 0;
maxthings = 0;
// Setup vertices for background image
SetupBackground();
// Set the rendertarget to the things texture
thingssurface = thingstex.GetSurfaceLevel(0);
if(graphics.StartRendering(clear, 0, thingssurface, null))
{
// Ready for rendering
return true;
}
else
{
// Can't render!
Finish();
return false;
}
}
else
{
// Can't render!
Finish();
return false;
}
}
// This ends a drawing session
public void Finish()
{
// Stop rendering
graphics.FinishRendering();
// Release rendertarget
try
{
graphics.Device.SetDepthStencilSurface(graphics.DepthBuffer);
graphics.Device.SetRenderTarget(0, graphics.BackBuffer);
}
catch(Exception) { }
// Clean up
if(plottertex != null) plottertex.UnlockRectangle(0);
if(plotlocked.Data != null) plotlocked.Data.Dispose();
if(thingssurface != null) thingssurface.Dispose();
thingssurface = null;
plotter = null;
}
// This adds a thing in the things buffer for rendering
public void RenderThing(Thing t, PixelColor c)
{
@ -919,7 +983,7 @@ namespace CodeImp.DoomBuilder.Rendering
thingsvertices.Unlock();
stream.Dispose();
}
// Thing added, render it
RenderThingsBatch(numthings, 1);
numthings++;
@ -932,7 +996,7 @@ namespace CodeImp.DoomBuilder.Rendering
FlatVertex[] verts = new FlatVertex[things.Count * 12];
DataStream stream;
int addcount = 0;
// Make sure there is enough memory reserved
ReserveThingsMemory(numthings + things.Count, true);
@ -946,7 +1010,7 @@ namespace CodeImp.DoomBuilder.Rendering
addcount++;
}
}
// Store vertices in buffer
if(thingsvertices != null)
{
@ -955,44 +1019,170 @@ namespace CodeImp.DoomBuilder.Rendering
thingsvertices.Unlock();
stream.Dispose();
}
// Things added, render them
RenderThingsBatch(numthings, addcount);
numthings += addcount;
}
#endregion
#region ================== Overlay
// This renders a rectangle with given border size and color
public void RenderRectangle(RectangleF rect, float bordersize, PixelColor c)
{
FlatQuad[] quads = new FlatQuad[4];
/*
* Rectangle setup:
*
* --------------------------
* |___________0____________|
* | | | |
* | | | |
* | | | |
* | 2| |3 |
* | | | |
* | | | |
* |__|__________________|__|
* | 1 |
* --------------------------
*
* Don't you just love ASCII art?
*/
// Calculate positions
Vector2D lt = new Vector2D(rect.Left, rect.Top);
Vector2D rb = new Vector2D(rect.Right, rect.Bottom);
lt = lt.GetTransformed(translatex, translatey, scale, -scale);
rb = rb.GetTransformed(translatex, translatey, scale, -scale);
float bw = bordersize;
// Make quads
quads[0] = new FlatQuad(PrimitiveType.TriangleList, lt.x, lt.y, rb.x, lt.y + bw);
quads[1] = new FlatQuad(PrimitiveType.TriangleList, lt.x, rb.y - bw, rb.x, rb.y);
quads[2] = new FlatQuad(PrimitiveType.TriangleList, lt.x, lt.y + bw, lt.x + bw, rb.y);
quads[3] = new FlatQuad(PrimitiveType.TriangleList, rb.x - bw, lt.y + bw, rb.x, rb.y - bw);
quads[0].SetColors(c.ToInt());
quads[1].SetColors(c.ToInt());
quads[2].SetColors(c.ToInt());
quads[3].SetColors(c.ToInt());
// Set renderstates for rendering
graphics.Device.SetRenderState(RenderState.CullMode, Cull.None);
graphics.Device.SetRenderState(RenderState.ZEnable, false);
graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, false);
graphics.Device.SetRenderState(RenderState.AlphaTestEnable, false);
graphics.Device.SetRenderState(RenderState.TextureFactor, -1);
// Draw
graphics.Shaders.Color2D.Begin();
graphics.Shaders.Color2D.BeginPass(0);
quads[0].Render(graphics);
quads[1].Render(graphics);
quads[2].Render(graphics);
quads[3].Render(graphics);
graphics.Shaders.Color2D.EndPass();
graphics.Shaders.Color2D.End();
}
// This renders a rectangle with given border size and color
public void RenderRectangle(RectangleF rect, float bordersize, PixelColor c, bool transformrect)
{
FlatQuad[] quads = new FlatQuad[4];
/*
* Rectangle setup:
*
* --------------------------
* |___________0____________|
* | | | |
* | | | |
* | | | |
* | 2| |3 |
* | | | |
* | | | |
* |__|__________________|__|
* | 1 |
* --------------------------
*
* Don't you just love ASCII art?
*/
// Calculate positions
Vector2D lt = new Vector2D(rect.Left, rect.Top);
Vector2D rb = new Vector2D(rect.Right, rect.Bottom);
if(transformrect)
{
lt = lt.GetTransformed(translatex, translatey, scale, -scale);
rb = rb.GetTransformed(translatex, translatey, scale, -scale);
}
// Make quads
quads[0] = new FlatQuad(PrimitiveType.TriangleList, lt.x, lt.y, rb.x, lt.y + bordersize);
quads[1] = new FlatQuad(PrimitiveType.TriangleList, lt.x, rb.y - bordersize, rb.x, rb.y);
quads[2] = new FlatQuad(PrimitiveType.TriangleList, lt.x, lt.y + bordersize, lt.x + bordersize, rb.y);
quads[3] = new FlatQuad(PrimitiveType.TriangleList, rb.x - bordersize, lt.y + bordersize, rb.x, rb.y - bordersize);
quads[0].SetColors(c.ToInt());
quads[1].SetColors(c.ToInt());
quads[2].SetColors(c.ToInt());
quads[3].SetColors(c.ToInt());
// Set renderstates for rendering
graphics.Device.SetRenderState(RenderState.CullMode, Cull.None);
graphics.Device.SetRenderState(RenderState.ZEnable, false);
graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, false);
graphics.Device.SetRenderState(RenderState.AlphaTestEnable, false);
graphics.Device.SetRenderState(RenderState.TextureFactor, -1);
// Draw
graphics.Shaders.Color2D.Begin();
graphics.Shaders.Color2D.BeginPass(0);
quads[0].Render(graphics);
quads[1].Render(graphics);
quads[2].Render(graphics);
quads[3].Render(graphics);
graphics.Shaders.Color2D.EndPass();
graphics.Shaders.Color2D.End();
}
#endregion
#region ================== Geometry
// This renders the linedefs of a sector with special color
public void RenderSector(Sector s, PixelColor c)
public void PlotSector(Sector s, PixelColor c)
{
// Go for all sides in the sector
foreach(Sidedef sd in s.Sidedefs)
{
// Render this linedef
RenderLinedef(sd.Line, c);
PlotLinedef(sd.Line, c);
// Render the two vertices on top
RenderVertex(sd.Line.Start, DetermineVertexColor(sd.Line.Start));
RenderVertex(sd.Line.End, DetermineVertexColor(sd.Line.End));
PlotVertex(sd.Line.Start, DetermineVertexColor(sd.Line.Start));
PlotVertex(sd.Line.End, DetermineVertexColor(sd.Line.End));
}
}
// This renders the linedefs of a sector
public void RenderSector(Sector s)
public void PlotSector(Sector s)
{
// Go for all sides in the sector
foreach(Sidedef sd in s.Sidedefs)
{
// Render this linedef
RenderLinedef(sd.Line, DetermineLinedefColor(sd.Line));
PlotLinedef(sd.Line, DetermineLinedefColor(sd.Line));
// Render the two vertices on top
RenderVertex(sd.Line.Start, DetermineVertexColor(sd.Line.Start));
RenderVertex(sd.Line.End, DetermineVertexColor(sd.Line.End));
PlotVertex(sd.Line.Start, DetermineVertexColor(sd.Line.Start));
PlotVertex(sd.Line.End, DetermineVertexColor(sd.Line.End));
}
}
// This renders a simple line
public void RenderLine(Vector2D start, Vector2D end, PixelColor c)
public void PlotLine(Vector2D start, Vector2D end, PixelColor c)
{
// Transform coordinates
Vector2D v1 = start.GetTransformed(translatex, translatey, scale, -scale);
@ -1003,7 +1193,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// This renders a single linedef
public void RenderLinedef(Linedef l, PixelColor c)
public void PlotLinedef(Linedef l, PixelColor c)
{
// Transform vertex coordinates
Vector2D v1 = l.Start.Position.GetTransformed(translatex, translatey, scale, -scale);
@ -1023,14 +1213,14 @@ namespace CodeImp.DoomBuilder.Rendering
}
// This renders a set of linedefs
public void RenderLinedefSet(ICollection<Linedef> linedefs)
public void PlotLinedefSet(ICollection<Linedef> linedefs)
{
// Go for all linedefs
foreach(Linedef l in linedefs) RenderLinedef(l, DetermineLinedefColor(l));
foreach(Linedef l in linedefs) PlotLinedef(l, DetermineLinedefColor(l));
}
// This renders a single vertex
public void RenderVertex(Vertex v, int colorindex)
public void PlotVertex(Vertex v, int colorindex)
{
// Transform vertex coordinates
Vector2D nv = v.Position.GetTransformed(translatex, translatey, scale, -scale);
@ -1040,7 +1230,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// This renders a single vertex at specified coordinates
public void RenderVertexAt(Vector2D v, int colorindex)
public void PlotVertexAt(Vector2D v, int colorindex)
{
// Transform vertex coordinates
Vector2D nv = v.GetTransformed(translatex, translatey, scale, -scale);
@ -1050,10 +1240,10 @@ namespace CodeImp.DoomBuilder.Rendering
}
// This renders a set of vertices
public void RenderVerticesSet(ICollection<Vertex> vertices)
public void PlotVerticesSet(ICollection<Vertex> vertices)
{
// Go for all vertices
foreach(Vertex v in vertices) RenderVertex(v, DetermineVertexColor(v));
foreach(Vertex v in vertices) PlotVertex(v, DetermineVertexColor(v));
}
#endregion

View file

@ -53,6 +53,7 @@ namespace CodeImp.DoomBuilder.Rendering
private Display2DShader display2dshader;
private Things2DShader things2dshader;
private World3DShader world3dshader;
private Color2DShader color2dshader;
// Device
private D3DDevice device;
@ -69,6 +70,7 @@ namespace CodeImp.DoomBuilder.Rendering
public Display2DShader Display2D { get { return display2dshader; } }
public Things2DShader Things2D { get { return things2dshader; } }
public World3DShader World3D { get { return world3dshader; } }
public Color2DShader Color2D { get { return color2dshader; } }
public bool IsDisposed { get { return isdisposed; } }
#endregion
@ -119,6 +121,7 @@ namespace CodeImp.DoomBuilder.Rendering
display2dshader.Dispose();
things2dshader.Dispose();
world3dshader.Dispose();
color2dshader.Dispose();
}
// Load resources
@ -135,6 +138,7 @@ namespace CodeImp.DoomBuilder.Rendering
display2dshader = new Display2DShader(this);
things2dshader = new Things2DShader(this);
world3dshader = new World3DShader(this);
color2dshader = new Color2DShader(this);
}
#endregion

View file

@ -0,0 +1,26 @@
// 2D color-only rendering shader
// Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
// Pixel input data
struct PixelData
{
float4 pos : POSITION;
float4 color : COLOR0;
float2 uv : TEXCOORD0;
};
// Pixel shader
float4 ps_normal(PixelData pd) : COLOR
{
return pd.color;
}
// Technique for shader model 2.0
technique SM20
{
pass p0
{
VertexShader = null;
PixelShader = compile ps_2_0 ps_normal();
}
}