Example #1
0
        private static void WriteShader(BBData data, ShaderInfo si, StringsChunkBuilder strings)
        {
            var se = new ShaderEntry
            {
                Name           = strings.GetOffset(si.Name),
                Type           = si.Type.Encode(),
                AttributeCount = (uint)si.Attributes.Length
            };

            unsafe
            {
                se.GLSL_ES.VertexSource   = strings.GetOffset(si.Code.GLSL_ES.VertexShader);
                se.GLSL_ES.FragmentSource = strings.GetOffset(si.Code.GLSL_ES.FragmentShader);
                se.GLSL.VertexSource      = strings.GetOffset(si.Code.GLSL.VertexShader);
                se.GLSL.FragmentSource    = strings.GetOffset(si.Code.GLSL.FragmentShader);
                se.HLSL9.VertexSource     = strings.GetOffset(si.Code.HLSL9.VertexShader);
                se.HLSL9.FragmentSource   = strings.GetOffset(si.Code.HLSL9.FragmentShader);
            }
            var tmp = new BinBuffer();

            tmp.Write(se);
            data.Buffer.Write(tmp, 0, tmp.Size - 4, 0); // TODO
            foreach (var attr in si.Attributes)
            {
                data.Buffer.Write(strings.GetOffset(attr));
            }
            data.Buffer.Write(2); // TODO: ShaderEntry2
            for (int i = 0; i < 12; i++)
            {
                data.Buffer.Write(0);
            }
        }
Example #2
0
        /// <summary>
        /// Gets the host shader for the guest shader code,
        /// or the default value for the type if not found.
        /// </summary>
        /// <param name="pack">Pack with spans of guest shader code</param>
        /// <param name="hash">Calculated hash of all the shader code on the pack</param>
        /// <returns>Host shader, or the default value if not found</returns>
        public T Get(ShaderPack pack, out int hash)
        {
            Fnv1a hasher = new Fnv1a();

            hasher.Initialize();

            for (int index = 0; index < pack.Count; index++)
            {
                hasher.Add(pack[index]);
            }

            hash = hasher.Hash;

            if (_shaders.TryGetValue(hash, out List <ShaderEntry> list))
            {
                for (int index = 0; index < list.Count; index++)
                {
                    ShaderEntry entry = list[index];

                    if (entry.CodeEquals(pack))
                    {
                        return(entry.Shader);
                    }
                }
            }

            return(default);