Fixed: line can be either dotted or smoothed

This commit is contained in:
ZZYZX 2019-12-15 07:12:38 +02:00
parent ca75897bc5
commit d1ff6bcc36
7 changed files with 612 additions and 535 deletions

View file

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio 14
VisualStudioVersion = 16.0.29201.188 VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Builder", "Source\Core\Builder.csproj", "{818B3D10-F791-4C3F-9AF5-BB2D0079B63C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Builder", "Source\Core\Builder.csproj", "{818B3D10-F791-4C3F-9AF5-BB2D0079B63C}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
@ -322,6 +322,28 @@ Global
{29C8D76F-DE3D-482D-AD7D-B86BBD0824DE}.Release|x64.Build.0 = Release|x64 {29C8D76F-DE3D-482D-AD7D-B86BBD0824DE}.Release|x64.Build.0 = Release|x64
{29C8D76F-DE3D-482D-AD7D-B86BBD0824DE}.Release|x86.ActiveCfg = Release|Win32 {29C8D76F-DE3D-482D-AD7D-B86BBD0824DE}.Release|x86.ActiveCfg = Release|Win32
{29C8D76F-DE3D-482D-AD7D-B86BBD0824DE}.Release|x86.Build.0 = Release|Win32 {29C8D76F-DE3D-482D-AD7D-B86BBD0824DE}.Release|x86.Build.0 = Release|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug + Profiler|Any CPU.ActiveCfg = Release|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug + Profiler|Any CPU.Build.0 = Release|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug + Profiler|x64.ActiveCfg = Debug|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug + Profiler|x64.Build.0 = Debug|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug + Profiler|x86.ActiveCfg = Debug|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug + Profiler|x86.Build.0 = Debug|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug|Any CPU.ActiveCfg = Debug|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug|x64.ActiveCfg = Debug|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug|x64.Build.0 = Debug|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug|x86.ActiveCfg = Debug|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Debug|x86.Build.0 = Debug|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Release + Profiler|Any CPU.ActiveCfg = Release|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Release + Profiler|Any CPU.Build.0 = Release|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Release + Profiler|x64.ActiveCfg = Release|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Release + Profiler|x64.Build.0 = Release|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Release + Profiler|x86.ActiveCfg = Release|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Release + Profiler|x86.Build.0 = Release|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Release|Any CPU.ActiveCfg = Release|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Release|x64.ActiveCfg = Release|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Release|x64.Build.0 = Release|x64
{78938655-9807-485E-9D4B-46226DC7AD27}.Release|x86.ActiveCfg = Release|Win32
{78938655-9807-485E-9D4B-46226DC7AD27}.Release|x86.Build.0 = Release|Win32
{88CFD996-027B-4CBE-9828-26B2728B6127}.Debug + Profiler|Any CPU.ActiveCfg = Debug|Any CPU {88CFD996-027B-4CBE-9828-26B2728B6127}.Debug + Profiler|Any CPU.ActiveCfg = Debug|Any CPU
{88CFD996-027B-4CBE-9828-26B2728B6127}.Debug + Profiler|Any CPU.Build.0 = Debug|Any CPU {88CFD996-027B-4CBE-9828-26B2728B6127}.Debug + Profiler|Any CPU.Build.0 = Debug|Any CPU
{88CFD996-027B-4CBE-9828-26B2728B6127}.Debug + Profiler|x64.ActiveCfg = Debug|x64 {88CFD996-027B-4CBE-9828-26B2728B6127}.Debug + Profiler|x64.ActiveCfg = Debug|x64

View file

@ -1509,45 +1509,5 @@
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<PropertyGroup> <PropertyGroup>
<PreBuildEvent>echo Current Output Directory: %25cd%25
echo Copying platform-appropriate DevIL.dll file.
copy /Y ..\DevIL\$(PlatformName)\DevIL.dll .\
echo Copying platform-appropriate SlimDX.dll file.
copy /Y ..\SlimDX\$(PlatformName)\SlimDX.dll .\
echo Copying platform-appropriate Updater.ini.
copy /Y ..\UpdaterConfig\Updater-$(PlatformName).ini Updater.ini</PreBuildEvent>
<PostBuildEvent>if exist "%25VS140COMNTOOLS%25" goto tools140
if exist "%25VS120COMNTOOLS%25" goto tools120
if exist "%25VS110COMNTOOLS%25" goto tools110
if exist "%25VS100COMNTOOLS%25" goto tools100
if exist "%25VS90COMNTOOLS%25" goto tools90
if exist "%25VSAPPIDDIR%25" goto tools17
:tools17
call "%25VSAPPIDDIR%25..\Tools\vsdevcmd" -arch=x86
goto end
:tools140
call "%25VS140COMNTOOLS%25vsvars32.bat"
goto end
:tools120
call "%25VS120COMNTOOLS%25vsvars32.bat"
goto end
:tools110
call "%25VS110COMNTOOLS%25vsvars32.bat"
goto end
:tools100
call "%25VS100COMNTOOLS%25vsvars32.bat"
goto end
:tools90
call "%25VS90COMNTOOLS%25vsvars32.bat"
goto end
:end
editbin.exe /NOLOGO /LARGEADDRESSAWARE "$(TargetPath)"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View file

@ -42,7 +42,7 @@ namespace CodeImp.DoomBuilder.Rendering
public void DrawContents(RenderDevice graphics) public void DrawContents(RenderDevice graphics)
{ {
if (clear == false && vertices.Count == 0) if (clear == false && Lists.Count == 0)
return; return;
var projmat = Matrix.Scaling(2.0f / this.Texture.Width, 2.0f / this.Texture.Height, 1.0f) * Matrix.Translation(-1.0f, -1.0f, 0.0f); var projmat = Matrix.Scaling(2.0f / this.Texture.Width, 2.0f / this.Texture.Height, 1.0f) * Matrix.Translation(-1.0f, -1.0f, 0.0f);
@ -54,12 +54,30 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetBlendOperation(BlendOperation.Add); graphics.SetBlendOperation(BlendOperation.Add);
graphics.SetSourceBlend(Blend.SourceAlpha); graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.InverseSourceAlpha); graphics.SetDestinationBlend(Blend.InverseSourceAlpha);
graphics.Draw(PrimitiveType.TriangleList, 0, vertices.Count / 3, vertices.ToArray()); for (int i = 0; i < Lists.Count; i++)
{
PrimitiveType pt = Lists[i].PrimitiveType;
List<FlatVertex> vertices = Lists[i].Vertices;
int cnt = vertices.Count;
switch (pt)
{
case PrimitiveType.TriangleList:
cnt /= 3;
break;
case PrimitiveType.LineList:
cnt /= 2;
break;
case PrimitiveType.TriangleStrip:
cnt = 1;
break;
}
graphics.Draw(Lists[i].PrimitiveType, 0, cnt, vertices.ToArray());
}
graphics.SetAlphaBlendEnable(false); graphics.SetAlphaBlendEnable(false);
graphics.FinishRendering(); graphics.FinishRendering();
clear = false; clear = false;
vertices.Clear(); Lists.Clear();
} }
private int TransformY(int y) private int TransformY(int y)
@ -67,11 +85,9 @@ namespace CodeImp.DoomBuilder.Rendering
return this.Texture.Height - y; return this.Texture.Height - y;
} }
void DrawLine(int x0, int y0, int x1, int y1, int c, bool dotted = false) // non-dotted line may be smoothed
void DrawSmoothedLine(int x0, int y0, int x1, int y1, int c)
{ {
y0 = TransformY(y0);
y1 = TransformY(y1);
var v = new FlatVertex(); var v = new FlatVertex();
v.c = c; v.c = c;
@ -105,28 +121,73 @@ namespace CodeImp.DoomBuilder.Rendering
float xx1 = x1 + 0.5f + dx; float xx1 = x1 + 0.5f + dx;
float yy1 = y1 + 0.5f + dy; float yy1 = y1 + 0.5f + dy;
float start, end;
if (!dotted)
{
start = 0.5f;
end = 0.5f;
}
else
{
start = 0.0f;
end = len;
}
float lineextent = 3.0f; // line width in shader + 1 float lineextent = 3.0f; // line width in shader + 1
nx *= lineextent; nx *= lineextent;
ny *= lineextent; ny *= lineextent;
v.u = start; v.v = -lineextent; v.x = xx0 - nx; v.y = yy0 - ny; vertices.Add(v); v.u = 0.5f;
v.u = start; v.v = lineextent; v.x = xx0 + nx; v.y = yy0 + ny; vertices.Add(v);
v.u = end; v.v = lineextent; v.x = xx1 + nx; v.y = yy1 + ny; vertices.Add(v); v.v = -lineextent; v.x = xx0 - nx; v.y = yy0 - ny; AddVertex(PrimitiveType.TriangleList, v);
vertices.Add(v); v.v = lineextent; v.x = xx0 + nx; v.y = yy0 + ny; AddVertex(PrimitiveType.TriangleList, v);
v.u = end; v.v = -lineextent; v.x = xx1 - nx; v.y = yy1 - ny; vertices.Add(v); v.v = lineextent; v.x = xx1 + nx; v.y = yy1 + ny; AddVertex(PrimitiveType.TriangleList, v);
v.u = start; v.v = -lineextent; v.x = xx0 - nx; v.y = yy0 - ny; vertices.Add(v); AddVertex(PrimitiveType.TriangleList, v);
v.v = -lineextent; v.x = xx1 - nx; v.y = yy1 - ny; AddVertex(PrimitiveType.TriangleList, v);
v.v = -lineextent; v.x = xx0 - nx; v.y = yy0 - ny; AddVertex(PrimitiveType.TriangleList, v);
}
void DrawLine(int x0, int y0, int x1, int y1, int c, bool dotted = false)
{
y0 = TransformY(y0);
y1 = TransformY(y1);
if (!dotted)
{
DrawSmoothedLine(x0, y0, x1, y1, c);
return;
}
var v = new FlatVertex();
v.c = c;
float nx, ny, len;
if (x0 == x1)
{
nx = 1.0f;
ny = 0.0f;
len = y1 - y0;
}
else if (y0 == y1)
{
nx = 0.0f;
ny = 1.0f;
len = x1 - x0;
}
else
{
nx = (float)(y1 - y0);
ny = (float)-(x1 - x0);
len = (float)Math.Sqrt(nx * nx + ny * ny);
nx /= len;
ny /= len;
}
float xx0 = x0 + 0.5f;
float yy0 = y0 + 0.5f;
float xx1 = x1 + 0.5f;
float yy1 = y1 + 0.5f;
float dotType = 0;
if (dotted)
{
if (Math.Abs(ny) > Math.Abs(nx))
dotType = -1;
else dotType = -2;
}
v.u = dotType; v.v = 0; v.x = xx0; v.y = yy0;
AddVertex(PrimitiveType.LineList, v);
v.u = dotType; v.v = 0; v.x = xx1; v.y = yy1;
AddVertex(PrimitiveType.LineList, v);
} }
void FillBox(int x0, int y0, int x1, int y1, int c) void FillBox(int x0, int y0, int x1, int y1, int c)
@ -139,12 +200,12 @@ namespace CodeImp.DoomBuilder.Rendering
v.u = 0.5f; v.u = 0.5f;
v.v = 0.0f; v.v = 0.0f;
v.x = x0; v.y = y0; vertices.Add(v); v.x = x0; v.y = y0; AddVertex(PrimitiveType.TriangleList, v);
v.x = x1; v.y = y0; vertices.Add(v); v.x = x1; v.y = y0; AddVertex(PrimitiveType.TriangleList, v);
v.x = x1; v.y = y1; vertices.Add(v); v.x = x1; v.y = y1; AddVertex(PrimitiveType.TriangleList, v);
vertices.Add(v); AddVertex(PrimitiveType.TriangleList, v);
v.x = x0; v.y = y1; vertices.Add(v); v.x = x0; v.y = y1; AddVertex(PrimitiveType.TriangleList, v);
v.x = x0; v.y = y0; vertices.Add(v); v.x = x0; v.y = y0; AddVertex(PrimitiveType.TriangleList, v);
} }
public void DrawVertexSolid(int x, int y, int size, PixelColor c, PixelColor l, PixelColor d) public void DrawVertexSolid(int x, int y, int size, PixelColor c, PixelColor l, PixelColor d)
@ -214,7 +275,26 @@ namespace CodeImp.DoomBuilder.Rendering
} }
bool clear = true; bool clear = true;
List<FlatVertex> vertices = new List<FlatVertex>(); //
private struct PlotVertexList
{
public PrimitiveType PrimitiveType;
public List<FlatVertex> Vertices;
}
private List<PlotVertexList> Lists = new List<PlotVertexList>();
private void AddVertex(PrimitiveType t, FlatVertex v)
{
if (Lists.Count == 0 || Lists[Lists.Count-1].PrimitiveType != t)
{
PlotVertexList vxlist;
vxlist.PrimitiveType = t;
vxlist.Vertices = new List<FlatVertex>();
Lists.Add(vxlist);
}
Lists[Lists.Count - 1].Vertices.Add(v);
}
const int DASH_INTERVAL = 16; const int DASH_INTERVAL = 16;
} }

View file

@ -21,7 +21,7 @@
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{78938655-9807-485E-9D4B-46226DC7AD27}</ProjectGuid> <ProjectGuid>{78938655-9807-485E-9D4B-46226DC7AD27}</ProjectGuid>
<RootNamespace>BuilderNative</RootNamespace> <RootNamespace>BuilderNative</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

View file

@ -7,6 +7,7 @@ static const char* plotter_vs = R"(
out vec4 Color; out vec4 Color;
out vec2 UV; out vec2 UV;
out vec2 Pos;
uniform mat4 projection; uniform mat4 projection;
@ -15,20 +16,34 @@ static const char* plotter_vs = R"(
gl_Position = projection * vec4(AttrPosition, 1.0f); gl_Position = projection * vec4(AttrPosition, 1.0f);
Color = AttrColor; Color = AttrColor;
UV = AttrUV; UV = AttrUV;
Pos = AttrPosition.xy;
} }
)"; )";
const char* plotter_ps = R"( const char* plotter_ps = R"(
in vec4 Color; in vec4 Color;
in vec2 UV; in vec2 UV;
in vec2 Pos;
out vec4 FragColor; out vec4 FragColor;
uniform vec4 rendersettings;
void main() void main()
{ {
if (UV.x < 0)
{
float yFrac = -(UV.x + 1);
vec2 tPos = vec2(
gl_FragCoord.x,
gl_FragCoord.y
);
// line stipple // line stipple
if (mod(UV.x, 2.0) > 1.0) if (mod(floor(mix(tPos.x, tPos.y, yFrac)), 2.0) > 0f)
discard; discard;
}
// line smoothing // line smoothing
float linewidth = 3.0; float linewidth = 3.0;

View file

@ -21,7 +21,7 @@
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{29C8D76F-DE3D-482D-AD7D-B86BBD0824DE}</ProjectGuid> <ProjectGuid>{29C8D76F-DE3D-482D-AD7D-B86BBD0824DE}</ProjectGuid>
<RootNamespace>vpo_dll</RootNamespace> <RootNamespace>vpo_dll</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">