Add a secondary texture coordinate to Vertex.
This commit is contained in:
@@ -69,12 +69,12 @@ namespace OpenRA.Graphics
|
|||||||
var eb = endColor.B / 255.0f;
|
var eb = endColor.B / 255.0f;
|
||||||
var ea = endColor.A / 255.0f;
|
var ea = endColor.A / 255.0f;
|
||||||
|
|
||||||
vertices[nv++] = new Vertex(start - corner + Offset, sr, sg, sb, sa);
|
vertices[nv++] = new Vertex(start - corner + Offset, sr, sg, sb, sa, 0, 0);
|
||||||
vertices[nv++] = new Vertex(start + corner + Offset, sr, sg, sb, sa);
|
vertices[nv++] = new Vertex(start + corner + Offset, sr, sg, sb, sa, 0, 0);
|
||||||
vertices[nv++] = new Vertex(end + corner + Offset, er, eg, eb, ea);
|
vertices[nv++] = new Vertex(end + corner + Offset, er, eg, eb, ea, 0, 0);
|
||||||
vertices[nv++] = new Vertex(end + corner + Offset, er, eg, eb, ea);
|
vertices[nv++] = new Vertex(end + corner + Offset, er, eg, eb, ea, 0, 0);
|
||||||
vertices[nv++] = new Vertex(end - corner + Offset, er, eg, eb, ea);
|
vertices[nv++] = new Vertex(end - corner + Offset, er, eg, eb, ea, 0, 0);
|
||||||
vertices[nv++] = new Vertex(start - corner + Offset, sr, sg, sb, sa);
|
vertices[nv++] = new Vertex(start - corner + Offset, sr, sg, sb, sa, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawLine(float2 start, float2 end, float width, Color color)
|
public void DrawLine(float2 start, float2 end, float width, Color color)
|
||||||
@@ -93,12 +93,12 @@ namespace OpenRA.Graphics
|
|||||||
var b = color.B / 255.0f;
|
var b = color.B / 255.0f;
|
||||||
var a = color.A / 255.0f;
|
var a = color.A / 255.0f;
|
||||||
|
|
||||||
vertices[nv++] = new Vertex(start - corner + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(start - corner + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(start + corner + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(start + corner + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(end + corner + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(end + corner + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(end + corner + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(end + corner + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(end - corner + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(end - corner + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(start - corner + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(start - corner + Offset, r, g, b, a, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -186,12 +186,12 @@ namespace OpenRA.Graphics
|
|||||||
if (nv + 6 > renderer.TempBufferSize)
|
if (nv + 6 > renderer.TempBufferSize)
|
||||||
Flush();
|
Flush();
|
||||||
|
|
||||||
vertices[nv++] = new Vertex(ca + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(ca + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(cb + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(cb + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(cc + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(cc + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(cc + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(cc + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(cd + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(cd + Offset, r, g, b, a, 0, 0);
|
||||||
vertices[nv++] = new Vertex(ca + Offset, r, g, b, a);
|
vertices[nv++] = new Vertex(ca + Offset, r, g, b, a, 0, 0);
|
||||||
|
|
||||||
// Advance line segment
|
// Advance line segment
|
||||||
end = next;
|
end = next;
|
||||||
@@ -243,12 +243,12 @@ namespace OpenRA.Graphics
|
|||||||
var cb = color.B / 255.0f;
|
var cb = color.B / 255.0f;
|
||||||
var ca = color.A / 255.0f;
|
var ca = color.A / 255.0f;
|
||||||
|
|
||||||
vertices[nv++] = new Vertex(a + Offset, cr, cg, cb, ca);
|
vertices[nv++] = new Vertex(a + Offset, cr, cg, cb, ca, 0, 0);
|
||||||
vertices[nv++] = new Vertex(b + Offset, cr, cg, cb, ca);
|
vertices[nv++] = new Vertex(b + Offset, cr, cg, cb, ca, 0, 0);
|
||||||
vertices[nv++] = new Vertex(c + Offset, cr, cg, cb, ca);
|
vertices[nv++] = new Vertex(c + Offset, cr, cg, cb, ca, 0, 0);
|
||||||
vertices[nv++] = new Vertex(c + Offset, cr, cg, cb, ca);
|
vertices[nv++] = new Vertex(c + Offset, cr, cg, cb, ca, 0, 0);
|
||||||
vertices[nv++] = new Vertex(d + Offset, cr, cg, cb, ca);
|
vertices[nv++] = new Vertex(d + Offset, cr, cg, cb, ca, 0, 0);
|
||||||
vertices[nv++] = new Vertex(a + Offset, cr, cg, cb, ca);
|
vertices[nv++] = new Vertex(a + Offset, cr, cg, cb, ca, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FillEllipse(RectangleF r, Color color, int vertices = 32)
|
public void FillEllipse(RectangleF r, Color color, int vertices = 32)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace OpenRA.Graphics
|
|||||||
for (var i = 0; i < vertices.Length; i++)
|
for (var i = 0; i < vertices.Length; i++)
|
||||||
{
|
{
|
||||||
var v = vertices[i];
|
var v = vertices[i];
|
||||||
vertices[i] = new Vertex(v.X, v.Y, v.Z, v.U, v.V, palette.TextureIndex, v.C);
|
vertices[i] = new Vertex(v.X, v.Y, v.Z, v.S, v.T, v.U, v.V, palette.TextureIndex, v.C);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var row = 0; row < map.MapSize.Y; row++)
|
for (var row = 0; row < map.MapSize.Y; row++)
|
||||||
|
|||||||
@@ -35,12 +35,12 @@ namespace OpenRA.Graphics
|
|||||||
if (r.Sheet.Type == SheetType.DualIndexed)
|
if (r.Sheet.Type == SheetType.DualIndexed)
|
||||||
attribC *= -1;
|
attribC *= -1;
|
||||||
|
|
||||||
vertices[nv] = new Vertex(a, r.Left, r.Top, paletteTextureIndex, attribC);
|
vertices[nv] = new Vertex(a, r.Left, r.Top, 0, 0, paletteTextureIndex, attribC);
|
||||||
vertices[nv + 1] = new Vertex(b, r.Right, r.Top, paletteTextureIndex, attribC);
|
vertices[nv + 1] = new Vertex(b, r.Right, r.Top, 0, 0, paletteTextureIndex, attribC);
|
||||||
vertices[nv + 2] = new Vertex(c, r.Right, r.Bottom, paletteTextureIndex, attribC);
|
vertices[nv + 2] = new Vertex(c, r.Right, r.Bottom, 0, 0, paletteTextureIndex, attribC);
|
||||||
vertices[nv + 3] = new Vertex(c, r.Right, r.Bottom, paletteTextureIndex, attribC);
|
vertices[nv + 3] = new Vertex(c, r.Right, r.Bottom, 0, 0, paletteTextureIndex, attribC);
|
||||||
vertices[nv + 4] = new Vertex(d, r.Left, r.Bottom, paletteTextureIndex, attribC);
|
vertices[nv + 4] = new Vertex(d, r.Left, r.Bottom, 0, 0, paletteTextureIndex, attribC);
|
||||||
vertices[nv + 5] = new Vertex(a, r.Left, r.Top, paletteTextureIndex, attribC);
|
vertices[nv + 5] = new Vertex(a, r.Left, r.Top, 0, 0, paletteTextureIndex, attribC);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FastCopyIntoChannel(Sprite dest, byte[] src) { FastCopyIntoChannel(dest, 0, src); }
|
public static void FastCopyIntoChannel(Sprite dest, byte[] src) { FastCopyIntoChannel(dest, 0, src); }
|
||||||
|
|||||||
@@ -16,14 +16,15 @@ namespace OpenRA.Graphics
|
|||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct Vertex
|
public struct Vertex
|
||||||
{
|
{
|
||||||
public readonly float X, Y, Z, U, V, P, C;
|
public readonly float X, Y, Z, S, T, U, V, P, C;
|
||||||
|
|
||||||
public Vertex(float3 xyz, float u, float v, float p, float c)
|
public Vertex(float3 xyz, float s, float t, float u, float v, float p, float c)
|
||||||
: this(xyz.X, xyz.Y, xyz.Z, u, v, p, c) { }
|
: this(xyz.X, xyz.Y, xyz.Z, s, t, u, v, p, c) { }
|
||||||
|
|
||||||
public Vertex(float x, float y, float z, float u, float v, float p, float c)
|
public Vertex(float x, float y, float z, float s, float t, float u, float v, float p, float c)
|
||||||
{
|
{
|
||||||
X = x; Y = y; Z = z;
|
X = x; Y = y; Z = z;
|
||||||
|
S = s; T = t;
|
||||||
U = u; V = v;
|
U = u; V = v;
|
||||||
P = p; C = c;
|
P = p; C = c;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,12 +95,12 @@ namespace OpenRA.Graphics
|
|||||||
var channelC = ChannelSelect[(int)s.Channel + 1];
|
var channelC = ChannelSelect[(int)s.Channel + 1];
|
||||||
return new Vertex[6]
|
return new Vertex[6]
|
||||||
{
|
{
|
||||||
new Vertex(coord(0, 0), s.Left, s.Top, channelP, channelC),
|
new Vertex(coord(0, 0), s.Left, s.Top, 0, 0, channelP, channelC),
|
||||||
new Vertex(coord(su, 0), s.Right, s.Top, channelP, channelC),
|
new Vertex(coord(su, 0), s.Right, s.Top, 0, 0, channelP, channelC),
|
||||||
new Vertex(coord(su, sv), s.Right, s.Bottom, channelP, channelC),
|
new Vertex(coord(su, sv), s.Right, s.Bottom, 0, 0, channelP, channelC),
|
||||||
new Vertex(coord(su, sv), s.Right, s.Bottom, channelP, channelC),
|
new Vertex(coord(su, sv), s.Right, s.Bottom, 0, 0, channelP, channelC),
|
||||||
new Vertex(coord(0, sv), s.Left, s.Bottom, channelP, channelC),
|
new Vertex(coord(0, sv), s.Left, s.Bottom, 0, 0, channelP, channelC),
|
||||||
new Vertex(coord(0, 0), s.Left, s.Top, channelP, channelC)
|
new Vertex(coord(0, 0), s.Left, s.Top, 0, 0, channelP, channelC)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ namespace OpenRA.Platforms.Default
|
|||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
OpenGL.glEnableVertexAttribArray(Shader.TexCoordAttributeIndex);
|
OpenGL.glEnableVertexAttribArray(Shader.TexCoordAttributeIndex);
|
||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
|
OpenGL.glEnableVertexAttribArray(Shader.TexMetadataAttributeIndex);
|
||||||
|
OpenGL.CheckGLError();
|
||||||
|
|
||||||
SDL.SDL_SetModState(SDL.SDL_Keymod.KMOD_NONE);
|
SDL.SDL_SetModState(SDL.SDL_Keymod.KMOD_NONE);
|
||||||
input = new Sdl2Input();
|
input = new Sdl2Input();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
{
|
{
|
||||||
public const int VertexPosAttributeIndex = 0;
|
public const int VertexPosAttributeIndex = 0;
|
||||||
public const int TexCoordAttributeIndex = 1;
|
public const int TexCoordAttributeIndex = 1;
|
||||||
|
public const int TexMetadataAttributeIndex = 2;
|
||||||
|
|
||||||
readonly Dictionary<string, int> samplers = new Dictionary<string, int>();
|
readonly Dictionary<string, int> samplers = new Dictionary<string, int>();
|
||||||
readonly Dictionary<int, ITexture> textures = new Dictionary<int, ITexture>();
|
readonly Dictionary<int, ITexture> textures = new Dictionary<int, ITexture>();
|
||||||
@@ -73,7 +74,8 @@ namespace OpenRA.Platforms.Default
|
|||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
OpenGL.glBindAttribLocation(program, TexCoordAttributeIndex, "aVertexTexCoord");
|
OpenGL.glBindAttribLocation(program, TexCoordAttributeIndex, "aVertexTexCoord");
|
||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
|
OpenGL.glBindAttribLocation(program, TexMetadataAttributeIndex, "aVertexTexMetadata");
|
||||||
|
OpenGL.CheckGLError();
|
||||||
OpenGL.glAttachShader(program, vertexShader);
|
OpenGL.glAttachShader(program, vertexShader);
|
||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
OpenGL.glAttachShader(program, fragmentShader);
|
OpenGL.glAttachShader(program, fragmentShader);
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ namespace OpenRA.Platforms.Default
|
|||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
OpenGL.glVertexAttribPointer(Shader.TexCoordAttributeIndex, 4, OpenGL.GL_FLOAT, false, VertexSize, new IntPtr(12));
|
OpenGL.glVertexAttribPointer(Shader.TexCoordAttributeIndex, 4, OpenGL.GL_FLOAT, false, VertexSize, new IntPtr(12));
|
||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
|
OpenGL.glVertexAttribPointer(Shader.TexMetadataAttributeIndex, 2, OpenGL.GL_FLOAT, false, VertexSize, new IntPtr(28));
|
||||||
|
OpenGL.CheckGLError();
|
||||||
}
|
}
|
||||||
|
|
||||||
~VertexBuffer()
|
~VertexBuffer()
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ uniform bool EnableDepthPreview;
|
|||||||
uniform float DepthTextureScale;
|
uniform float DepthTextureScale;
|
||||||
|
|
||||||
varying vec4 vTexCoord;
|
varying vec4 vTexCoord;
|
||||||
|
varying vec2 vTexMetadata;
|
||||||
varying vec4 vChannelMask;
|
varying vec4 vChannelMask;
|
||||||
varying vec4 vDepthMask;
|
varying vec4 vDepthMask;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 x = texture2D(DiffuseTexture, vTexCoord.st);
|
vec4 x = texture2D(DiffuseTexture, vTexCoord.st);
|
||||||
vec2 p = vec2(dot(x, vChannelMask), vTexCoord.p);
|
vec2 p = vec2(dot(x, vChannelMask), vTexMetadata.s);
|
||||||
vec4 c = texture2D(Palette, p);
|
vec4 c = texture2D(Palette, p);
|
||||||
|
|
||||||
// Discard any transparent fragments (both color and depth)
|
// Discard any transparent fragments (both color and depth)
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ uniform vec3 r1, r2;
|
|||||||
|
|
||||||
attribute vec4 aVertexPosition;
|
attribute vec4 aVertexPosition;
|
||||||
attribute vec4 aVertexTexCoord;
|
attribute vec4 aVertexTexCoord;
|
||||||
|
attribute vec2 aVertexTexMetadata;
|
||||||
varying vec4 vTexCoord;
|
varying vec4 vTexCoord;
|
||||||
|
varying vec2 vTexMetadata;
|
||||||
varying vec4 vChannelMask;
|
varying vec4 vChannelMask;
|
||||||
varying vec4 vDepthMask;
|
varying vec4 vDepthMask;
|
||||||
|
|
||||||
@@ -38,6 +40,7 @@ void main()
|
|||||||
{
|
{
|
||||||
gl_Position = vec4((aVertexPosition.xyz - Scroll.xyz) * r1 + r2, 1);
|
gl_Position = vec4((aVertexPosition.xyz - Scroll.xyz) * r1 + r2, 1);
|
||||||
vTexCoord = aVertexTexCoord;
|
vTexCoord = aVertexTexCoord;
|
||||||
vChannelMask = DecodeChannelMask(aVertexTexCoord.w);
|
vTexMetadata = aVertexTexMetadata;
|
||||||
vDepthMask = DecodeDepthChannelMask(aVertexTexCoord.w);
|
vChannelMask = DecodeChannelMask(aVertexTexMetadata.t);
|
||||||
|
vDepthMask = DecodeDepthChannelMask(aVertexTexMetadata.t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ uniform mat4 TransformMatrix;
|
|||||||
|
|
||||||
attribute vec4 aVertexPosition;
|
attribute vec4 aVertexPosition;
|
||||||
attribute vec4 aVertexTexCoord;
|
attribute vec4 aVertexTexCoord;
|
||||||
|
attribute vec2 aVertexTexMetadata;
|
||||||
varying vec4 vTexCoord;
|
varying vec4 vTexCoord;
|
||||||
varying vec4 vChannelMask;
|
varying vec4 vChannelMask;
|
||||||
varying vec4 vNormalsMask;
|
varying vec4 vNormalsMask;
|
||||||
@@ -19,6 +20,6 @@ void main()
|
|||||||
{
|
{
|
||||||
gl_Position = View*TransformMatrix*aVertexPosition;
|
gl_Position = View*TransformMatrix*aVertexPosition;
|
||||||
vTexCoord = aVertexTexCoord;
|
vTexCoord = aVertexTexCoord;
|
||||||
vChannelMask = DecodeMask(aVertexTexCoord.z);
|
vChannelMask = DecodeMask(aVertexTexMetadata.s);
|
||||||
vNormalsMask = DecodeMask(aVertexTexCoord.w);
|
vNormalsMask = DecodeMask(aVertexTexMetadata.t);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user