diff --git a/OpenRA.Game/Graphics/RgbaColorRenderer.cs b/OpenRA.Game/Graphics/RgbaColorRenderer.cs index 1bd233ce80..2dc417c363 100644 --- a/OpenRA.Game/Graphics/RgbaColorRenderer.cs +++ b/OpenRA.Game/Graphics/RgbaColorRenderer.cs @@ -69,12 +69,12 @@ namespace OpenRA.Graphics var eb = endColor.B / 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); - vertices[nv++] = new Vertex(end + corner + Offset, er, eg, eb, ea); - vertices[nv++] = new Vertex(end + corner + Offset, er, eg, eb, ea); - vertices[nv++] = new Vertex(end - corner + Offset, er, eg, eb, ea); - 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, 0, 0); + vertices[nv++] = new Vertex(end + corner + Offset, er, eg, eb, ea, 0, 0); + vertices[nv++] = new Vertex(end + corner + Offset, er, eg, eb, ea, 0, 0); + vertices[nv++] = new Vertex(end - corner + Offset, er, eg, eb, ea, 0, 0); + vertices[nv++] = new Vertex(start - corner + Offset, sr, sg, sb, sa, 0, 0); } 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 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); - vertices[nv++] = new Vertex(end + corner + Offset, r, g, b, a); - vertices[nv++] = new Vertex(end + corner + Offset, r, g, b, a); - vertices[nv++] = new Vertex(end - corner + Offset, r, g, b, a); - 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, 0, 0); + vertices[nv++] = new Vertex(end + corner + Offset, r, g, b, a, 0, 0); + vertices[nv++] = new Vertex(end + corner + Offset, r, g, b, a, 0, 0); + vertices[nv++] = new Vertex(end - corner + Offset, r, g, b, a, 0, 0); + vertices[nv++] = new Vertex(start - corner + Offset, r, g, b, a, 0, 0); } /// @@ -186,12 +186,12 @@ namespace OpenRA.Graphics if (nv + 6 > renderer.TempBufferSize) Flush(); - vertices[nv++] = new Vertex(ca + Offset, r, g, b, a); - vertices[nv++] = new Vertex(cb + Offset, r, g, b, a); - vertices[nv++] = new Vertex(cc + Offset, r, g, b, a); - vertices[nv++] = new Vertex(cc + Offset, r, g, b, a); - vertices[nv++] = new Vertex(cd + Offset, r, g, b, a); - 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, 0, 0); + vertices[nv++] = new Vertex(cc + Offset, r, g, b, a, 0, 0); + vertices[nv++] = new Vertex(cc + Offset, r, g, b, a, 0, 0); + vertices[nv++] = new Vertex(cd + Offset, r, g, b, a, 0, 0); + vertices[nv++] = new Vertex(ca + Offset, r, g, b, a, 0, 0); // Advance line segment end = next; @@ -243,12 +243,12 @@ namespace OpenRA.Graphics var cb = color.B / 255.0f; var ca = color.A / 255.0f; - vertices[nv++] = new Vertex(a + Offset, cr, cg, cb, ca); - vertices[nv++] = new Vertex(b + Offset, cr, cg, cb, ca); - vertices[nv++] = new Vertex(c + Offset, cr, cg, cb, ca); - vertices[nv++] = new Vertex(c + Offset, cr, cg, cb, ca); - vertices[nv++] = new Vertex(d + Offset, cr, cg, cb, ca); - 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, 0, 0); + vertices[nv++] = new Vertex(c + Offset, cr, cg, cb, ca, 0, 0); + vertices[nv++] = new Vertex(c + Offset, cr, cg, cb, ca, 0, 0); + vertices[nv++] = new Vertex(d + Offset, cr, cg, cb, ca, 0, 0); + vertices[nv++] = new Vertex(a + Offset, cr, cg, cb, ca, 0, 0); } public void FillEllipse(RectangleF r, Color color, int vertices = 32) diff --git a/OpenRA.Game/Graphics/TerrainSpriteLayer.cs b/OpenRA.Game/Graphics/TerrainSpriteLayer.cs index 77b79eac27..25fa73d924 100644 --- a/OpenRA.Game/Graphics/TerrainSpriteLayer.cs +++ b/OpenRA.Game/Graphics/TerrainSpriteLayer.cs @@ -59,7 +59,7 @@ namespace OpenRA.Graphics for (var i = 0; i < vertices.Length; 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++) diff --git a/OpenRA.Game/Graphics/Util.cs b/OpenRA.Game/Graphics/Util.cs index 2f6bf48559..90b28c856d 100644 --- a/OpenRA.Game/Graphics/Util.cs +++ b/OpenRA.Game/Graphics/Util.cs @@ -35,12 +35,12 @@ namespace OpenRA.Graphics if (r.Sheet.Type == SheetType.DualIndexed) attribC *= -1; - vertices[nv] = new Vertex(a, r.Left, r.Top, paletteTextureIndex, attribC); - vertices[nv + 1] = new Vertex(b, r.Right, r.Top, paletteTextureIndex, attribC); - vertices[nv + 2] = new Vertex(c, r.Right, r.Bottom, paletteTextureIndex, attribC); - vertices[nv + 3] = new Vertex(c, r.Right, r.Bottom, paletteTextureIndex, attribC); - vertices[nv + 4] = new Vertex(d, r.Left, r.Bottom, paletteTextureIndex, attribC); - vertices[nv + 5] = 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, 0, 0, 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, 0, 0, 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, 0, 0, paletteTextureIndex, attribC); } public static void FastCopyIntoChannel(Sprite dest, byte[] src) { FastCopyIntoChannel(dest, 0, src); } diff --git a/OpenRA.Game/Graphics/Vertex.cs b/OpenRA.Game/Graphics/Vertex.cs index 206e50051d..96ffbdff28 100644 --- a/OpenRA.Game/Graphics/Vertex.cs +++ b/OpenRA.Game/Graphics/Vertex.cs @@ -16,14 +16,15 @@ namespace OpenRA.Graphics [StructLayout(LayoutKind.Sequential)] 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) - : this(xyz.X, xyz.Y, xyz.Z, u, v, p, c) { } + public Vertex(float3 xyz, float s, float t, float u, float v, float p, float 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; + S = s; T = t; U = u; V = v; P = p; C = c; } diff --git a/OpenRA.Game/Graphics/VoxelLoader.cs b/OpenRA.Game/Graphics/VoxelLoader.cs index 195ba9fe27..38c0cb3632 100644 --- a/OpenRA.Game/Graphics/VoxelLoader.cs +++ b/OpenRA.Game/Graphics/VoxelLoader.cs @@ -95,12 +95,12 @@ namespace OpenRA.Graphics var channelC = ChannelSelect[(int)s.Channel + 1]; return new Vertex[6] { - new Vertex(coord(0, 0), s.Left, s.Top, channelP, channelC), - new Vertex(coord(su, 0), s.Right, s.Top, channelP, channelC), - new Vertex(coord(su, sv), s.Right, s.Bottom, channelP, channelC), - new Vertex(coord(su, sv), s.Right, s.Bottom, channelP, channelC), - new Vertex(coord(0, sv), s.Left, s.Bottom, 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), + new Vertex(coord(su, 0), s.Right, s.Top, 0, 0, channelP, channelC), + new Vertex(coord(su, sv), s.Right, s.Bottom, 0, 0, channelP, channelC), + new Vertex(coord(su, sv), s.Right, s.Bottom, 0, 0, channelP, channelC), + new Vertex(coord(0, sv), s.Left, s.Bottom, 0, 0, channelP, channelC), + new Vertex(coord(0, 0), s.Left, s.Top, 0, 0, channelP, channelC) }; } diff --git a/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs b/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs index fec2a467d5..b77f9a795f 100644 --- a/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs +++ b/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs @@ -81,6 +81,8 @@ namespace OpenRA.Platforms.Default OpenGL.CheckGLError(); OpenGL.glEnableVertexAttribArray(Shader.TexCoordAttributeIndex); OpenGL.CheckGLError(); + OpenGL.glEnableVertexAttribArray(Shader.TexMetadataAttributeIndex); + OpenGL.CheckGLError(); SDL.SDL_SetModState(SDL.SDL_Keymod.KMOD_NONE); input = new Sdl2Input(); diff --git a/OpenRA.Platforms.Default/Shader.cs b/OpenRA.Platforms.Default/Shader.cs index 9facf102f4..cab8d30b32 100644 --- a/OpenRA.Platforms.Default/Shader.cs +++ b/OpenRA.Platforms.Default/Shader.cs @@ -20,6 +20,7 @@ namespace OpenRA.Platforms.Default { public const int VertexPosAttributeIndex = 0; public const int TexCoordAttributeIndex = 1; + public const int TexMetadataAttributeIndex = 2; readonly Dictionary samplers = new Dictionary(); readonly Dictionary textures = new Dictionary(); @@ -73,7 +74,8 @@ namespace OpenRA.Platforms.Default OpenGL.CheckGLError(); OpenGL.glBindAttribLocation(program, TexCoordAttributeIndex, "aVertexTexCoord"); OpenGL.CheckGLError(); - + OpenGL.glBindAttribLocation(program, TexMetadataAttributeIndex, "aVertexTexMetadata"); + OpenGL.CheckGLError(); OpenGL.glAttachShader(program, vertexShader); OpenGL.CheckGLError(); OpenGL.glAttachShader(program, fragmentShader); diff --git a/OpenRA.Platforms.Default/VertexBuffer.cs b/OpenRA.Platforms.Default/VertexBuffer.cs index 72b18d4243..32a487b209 100644 --- a/OpenRA.Platforms.Default/VertexBuffer.cs +++ b/OpenRA.Platforms.Default/VertexBuffer.cs @@ -87,6 +87,8 @@ namespace OpenRA.Platforms.Default OpenGL.CheckGLError(); OpenGL.glVertexAttribPointer(Shader.TexCoordAttributeIndex, 4, OpenGL.GL_FLOAT, false, VertexSize, new IntPtr(12)); OpenGL.CheckGLError(); + OpenGL.glVertexAttribPointer(Shader.TexMetadataAttributeIndex, 2, OpenGL.GL_FLOAT, false, VertexSize, new IntPtr(28)); + OpenGL.CheckGLError(); } ~VertexBuffer() diff --git a/glsl/shp.frag b/glsl/shp.frag index 8f0b102384..17fba1bb96 100644 --- a/glsl/shp.frag +++ b/glsl/shp.frag @@ -4,13 +4,14 @@ uniform bool EnableDepthPreview; uniform float DepthTextureScale; varying vec4 vTexCoord; +varying vec2 vTexMetadata; varying vec4 vChannelMask; varying vec4 vDepthMask; void main() { 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); // Discard any transparent fragments (both color and depth) diff --git a/glsl/shp.vert b/glsl/shp.vert index 8e46666dfa..bd1cae3d2e 100644 --- a/glsl/shp.vert +++ b/glsl/shp.vert @@ -3,7 +3,9 @@ uniform vec3 r1, r2; attribute vec4 aVertexPosition; attribute vec4 aVertexTexCoord; +attribute vec2 aVertexTexMetadata; varying vec4 vTexCoord; +varying vec2 vTexMetadata; varying vec4 vChannelMask; varying vec4 vDepthMask; @@ -38,6 +40,7 @@ void main() { gl_Position = vec4((aVertexPosition.xyz - Scroll.xyz) * r1 + r2, 1); vTexCoord = aVertexTexCoord; - vChannelMask = DecodeChannelMask(aVertexTexCoord.w); - vDepthMask = DecodeDepthChannelMask(aVertexTexCoord.w); + vTexMetadata = aVertexTexMetadata; + vChannelMask = DecodeChannelMask(aVertexTexMetadata.t); + vDepthMask = DecodeDepthChannelMask(aVertexTexMetadata.t); } diff --git a/glsl/vxl.vert b/glsl/vxl.vert index 07a84997b2..fa268ea186 100644 --- a/glsl/vxl.vert +++ b/glsl/vxl.vert @@ -3,6 +3,7 @@ uniform mat4 TransformMatrix; attribute vec4 aVertexPosition; attribute vec4 aVertexTexCoord; +attribute vec2 aVertexTexMetadata; varying vec4 vTexCoord; varying vec4 vChannelMask; varying vec4 vNormalsMask; @@ -19,6 +20,6 @@ void main() { gl_Position = View*TransformMatrix*aVertexPosition; vTexCoord = aVertexTexCoord; - vChannelMask = DecodeMask(aVertexTexCoord.z); - vNormalsMask = DecodeMask(aVertexTexCoord.w); + vChannelMask = DecodeMask(aVertexTexMetadata.s); + vNormalsMask = DecodeMask(aVertexTexMetadata.t); }