diff --git a/OpenRA.Game/Graphics/Model.cs b/OpenRA.Game/Graphics/Model.cs index 30ece91622..2e3893cf91 100644 --- a/OpenRA.Game/Graphics/Model.cs +++ b/OpenRA.Game/Graphics/Model.cs @@ -49,7 +49,7 @@ namespace OpenRA.Graphics IModel GetModel(string model); IModel GetModelSequence(string model, string sequence); bool HasModelSequence(string model, string sequence); - IVertexBuffer VertexBuffer { get; } + IVertexBuffer VertexBuffer { get; } } public interface IModelSequenceLoader @@ -64,7 +64,7 @@ namespace OpenRA.Graphics sealed class PlaceholderModelCache : IModelCache { - public IVertexBuffer VertexBuffer => throw new NotImplementedException(); + public IVertexBuffer VertexBuffer => throw new NotImplementedException(); public void Dispose() { } diff --git a/OpenRA.Game/Graphics/ModelVertex.cs b/OpenRA.Game/Graphics/ModelVertex.cs new file mode 100644 index 0000000000..b4f591d184 --- /dev/null +++ b/OpenRA.Game/Graphics/ModelVertex.cs @@ -0,0 +1,53 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Runtime.InteropServices; + +namespace OpenRA.Graphics +{ + [StructLayout(LayoutKind.Sequential)] + public readonly struct ModelVertex + { + // 3d position + public readonly float X, Y, Z; + + // Primary and secondary texture coordinates or RGBA color + public readonly float S, T, U, V; + + // Palette and channel flags + public readonly float P, C; + + public ModelVertex(in 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 ModelVertex(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; + } + } + + public sealed class ModelShaderBindings : ShaderBindings + { + public ModelShaderBindings() + : base("model") + { } + + public override ShaderVertexAttribute[] Attributes { get; } = new[] + { + new ShaderVertexAttribute("aVertexPosition", 3, 0), + new ShaderVertexAttribute("aVertexTexCoord", 4, 12), + new ShaderVertexAttribute("aVertexTexMetadata", 2, 28), + }; + } +} diff --git a/OpenRA.Game/Graphics/Vertex.cs b/OpenRA.Game/Graphics/Vertex.cs index c880a42296..c84163e343 100644 --- a/OpenRA.Game/Graphics/Vertex.cs +++ b/OpenRA.Game/Graphics/Vertex.cs @@ -61,19 +61,4 @@ namespace OpenRA.Graphics new ShaderVertexAttribute("aVertexTint", 4, 36) }; } - - public sealed class ModelShaderBindings : ShaderBindings - { - public ModelShaderBindings() - : base("model") - { } - - public override ShaderVertexAttribute[] Attributes { get; } = new[] - { - new ShaderVertexAttribute("aVertexPosition", 3, 0), - new ShaderVertexAttribute("aVertexTexCoord", 4, 12), - new ShaderVertexAttribute("aVertexTexMetadata", 2, 28), - new ShaderVertexAttribute("aVertexTint", 4, 36) - }; - } } diff --git a/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs b/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs index ebf1861392..5439763dd1 100644 --- a/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs +++ b/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs @@ -23,10 +23,10 @@ namespace OpenRA.Mods.Cnc.Graphics { static readonly float[] ChannelSelect = { 0.75f, 0.25f, -0.25f, -0.75f }; - readonly List vertices = new(); + readonly List vertices = new(); readonly Cache<(string, string), Voxel> voxels; readonly IReadOnlyFileSystem fileSystem; - IVertexBuffer vertexBuffer; + IVertexBuffer vertexBuffer; int totalVertexCount; int cachedVertexCount; @@ -50,14 +50,14 @@ namespace OpenRA.Mods.Cnc.Graphics { this.fileSystem = fileSystem; voxels = new Cache<(string, string), Voxel>(LoadFile); - vertices = new List(); + vertices = new List(); totalVertexCount = 0; cachedVertexCount = 0; sheetBuilder = CreateSheetBuilder(); } - Vertex[] GenerateSlicePlane(int su, int sv, Func first, Func second, Func coord) + ModelVertex[] GenerateSlicePlane(int su, int sv, Func first, Func second, Func coord) { var colors = new byte[su * sv]; var normals = new byte[su * sv]; @@ -86,18 +86,18 @@ namespace OpenRA.Mods.Cnc.Graphics var channelP = ChannelSelect[(int)s.Channel]; var channelC = ChannelSelect[(int)t.Channel]; - return new Vertex[6] + return new ModelVertex[6] { - new Vertex(coord(0, 0), s.Left, s.Top, t.Left, t.Top, channelP, channelC), - new Vertex(coord(su, 0), s.Right, s.Top, t.Right, t.Top, channelP, channelC), - new Vertex(coord(su, sv), s.Right, s.Bottom, t.Right, t.Bottom, channelP, channelC), - new Vertex(coord(su, sv), s.Right, s.Bottom, t.Right, t.Bottom, channelP, channelC), - new Vertex(coord(0, sv), s.Left, s.Bottom, t.Left, t.Bottom, channelP, channelC), - new Vertex(coord(0, 0), s.Left, s.Top, t.Left, t.Top, channelP, channelC) + new ModelVertex(coord(0, 0), s.Left, s.Top, t.Left, t.Top, channelP, channelC), + new ModelVertex(coord(su, 0), s.Right, s.Top, t.Right, t.Top, channelP, channelC), + new ModelVertex(coord(su, sv), s.Right, s.Bottom, t.Right, t.Bottom, channelP, channelC), + new ModelVertex(coord(su, sv), s.Right, s.Bottom, t.Right, t.Bottom, channelP, channelC), + new ModelVertex(coord(0, sv), s.Left, s.Bottom, t.Left, t.Bottom, channelP, channelC), + new ModelVertex(coord(0, 0), s.Left, s.Top, t.Left, t.Top, channelP, channelC) }; } - IEnumerable GenerateSlicePlanes(VxlLimb l) + IEnumerable GenerateSlicePlanes(VxlLimb l) { VxlElement? Get(int x, int y, int z) { @@ -170,7 +170,7 @@ namespace OpenRA.Mods.Cnc.Graphics public ModelRenderData GenerateRenderData(VxlLimb l) { - Vertex[] v; + ModelVertex[] v; try { v = GenerateSlicePlanes(l).SelectMany(x => x).ToArray(); @@ -195,12 +195,12 @@ namespace OpenRA.Mods.Cnc.Graphics public void RefreshBuffer() { vertexBuffer?.Dispose(); - vertexBuffer = Game.Renderer.CreateVertexBuffer(totalVertexCount); + vertexBuffer = Game.Renderer.CreateVertexBuffer(totalVertexCount); vertexBuffer.SetData(vertices.SelectMany(v => v).ToArray(), totalVertexCount); cachedVertexCount = totalVertexCount; } - public IVertexBuffer VertexBuffer + public IVertexBuffer VertexBuffer { get { diff --git a/OpenRA.Mods.Cnc/Graphics/VoxelModelSequenceLoader.cs b/OpenRA.Mods.Cnc/Graphics/VoxelModelSequenceLoader.cs index 5d45e236e4..8eea699f4c 100644 --- a/OpenRA.Mods.Cnc/Graphics/VoxelModelSequenceLoader.cs +++ b/OpenRA.Mods.Cnc/Graphics/VoxelModelSequenceLoader.cs @@ -114,7 +114,7 @@ namespace OpenRA.Mods.Cnc.Graphics return models[model].ContainsKey(sequence); } - public IVertexBuffer VertexBuffer => loader.VertexBuffer; + public IVertexBuffer VertexBuffer => loader.VertexBuffer; public void Dispose() { diff --git a/glsl/model.vert b/glsl/model.vert index ab111cd9f0..16aa02496f 100644 --- a/glsl/model.vert +++ b/glsl/model.vert @@ -7,7 +7,6 @@ uniform mat4 TransformMatrix; attribute vec4 aVertexPosition; attribute vec4 aVertexTexCoord; attribute vec2 aVertexTexMetadata; -attribute vec3 aVertexTint; varying vec4 vTexCoord; varying vec4 vChannelMask; varying vec4 vNormalsMask; @@ -15,7 +14,6 @@ varying vec4 vNormalsMask; in vec4 aVertexPosition; in vec4 aVertexTexCoord; in vec2 aVertexTexMetadata; -in vec3 aVertexTint; out vec4 vTexCoord; out vec4 vChannelMask; out vec4 vNormalsMask;