Exemple #1
0
            public void Prepare(Shader shader, ShaderProperties properties, bool prepareNeeded = true)
            {
                if (shader == null)
                {
                    return;
                }

                var index = 0;

                foreach (var key in Keys)
                {
                    var texture = Textures[key];
                    texture.Item1.Activate((uint)index);

                    if (prepareNeeded)
                    {
                        shader.SetScalar(key, index);
                    }

                    var overrideAtlasIndex = 0u;
                    var overridden         = properties?.TryGetAtlasIndex(key, out overrideAtlasIndex) ?? false;

                    if (overridden && overrideAtlasIndex >= texture.Item3)
                    {
                        throw new InvalidOperationException("Invalid atlas index.");
                    }

                    if (prepareNeeded || overridden)
                    {
                        var rank   = (uint)Math.Ceiling(Math.Sqrt(texture.Item3));
                        var offset = (overridden ? overrideAtlasIndex : texture.Item2).ToOffsets(rank);

                        var texture_offset = $"{key}_offset";
                        if (shader.IsUsing(texture_offset))
                        {
                            shader.SetVec2(texture_offset, offset.x, offset.y);
                        }
                        var texture_rank = $"{key}_rank";
                        if (shader.IsUsing(texture_rank))
                        {
                            shader.SetScalar(texture_rank, rank);
                        }
                    }

                    ++index;
                }
            }
Exemple #2
0
            public void Prepare(Shader shader, ShaderProperties properties, bool prepareNeeded = true)
            {
                if (shader == null)
                {
                    return;
                }
                if (!prepareNeeded)
                {
                    return;
                }

                foreach (var key in Keys)
                {
                    var val = Values[key];

                    switch (val.ValType)
                    {
                    case Value.Type.INT:                    shader.SetScalar(key, val.InnerVal.intv); break;

                    case Value.Type.UINT:                   shader.SetScalar(key, val.InnerVal.uintv); break;

                    case Value.Type.FLOAT:                  shader.SetScalar(key, val.InnerVal.floatv); break;

                    case Value.Type.INT_ARRAY:              shader.SetScalarArray(key, (int[])val.InnerVal.arrayv); break;

                    case Value.Type.UINT_ARRAY:             shader.SetScalarArray(key, (uint[])val.InnerVal.arrayv); break;

                    case Value.Type.FLOAT_ARRAY:    shader.SetScalarArray(key, (float[])val.InnerVal.arrayv); break;

                    case Value.Type.RGB:                    shader.SetVec3(key, val.InnerVal.vecv.x, val.InnerVal.vecv.y, val.InnerVal.vecv.z); break;

                    case Value.Type.RGBA:                   shader.SetVec4(key, val.InnerVal.vecv.x, val.InnerVal.vecv.y, val.InnerVal.vecv.z, val.InnerVal.vecv.w); break;

                    case Value.Type.VEC2:                   shader.SetVec2(key, val.InnerVal.vecv.x, val.InnerVal.vecv.y); break;

                    case Value.Type.VEC3:                   shader.SetVec3(key, val.InnerVal.vecv.x, val.InnerVal.vecv.y, val.InnerVal.vecv.z); break;

                    case Value.Type.VEC4:                   shader.SetVec4(key, val.InnerVal.vecv.x, val.InnerVal.vecv.y, val.InnerVal.vecv.z, val.InnerVal.vecv.w); break;

                    case Value.Type.RGB_ARRAY:              shader.SetVec3Array(key, (float[])val.InnerVal.arrayv); break;

                    case Value.Type.RGBA_ARRAY:             shader.SetVec4Array(key, (float[])val.InnerVal.arrayv); break;

                    case Value.Type.VEC2_ARRAY:             shader.SetVec2Array(key, (float[])val.InnerVal.arrayv); break;

                    case Value.Type.VEC3_ARRAY:             shader.SetVec3Array(key, (float[])val.InnerVal.arrayv); break;

                    case Value.Type.VEC4_ARRAY:             shader.SetVec4Array(key, (float[])val.InnerVal.arrayv); break;

                    case Value.Type.MAT2:                   shader.SetMat2(key, (float[])val.InnerVal.arrayv, false); break;

                    case Value.Type.MAT2_T:                 shader.SetMat2(key, (float[])val.InnerVal.arrayv, true); break;

                    case Value.Type.MAT3:                   shader.SetMat3(key, (float[])val.InnerVal.arrayv, false); break;

                    case Value.Type.MAT3_T:                 shader.SetMat3(key, (float[])val.InnerVal.arrayv, true); break;

                    case Value.Type.MAT4:                   shader.SetMat4(key, (float[])val.InnerVal.arrayv, false); break;

                    case Value.Type.MAT4_T:                 shader.SetMat4(key, (float[])val.InnerVal.arrayv, true); break;

                    case Value.Type.MAT2_ARRAY:             shader.SetMat2Array(key, (float[])val.InnerVal.arrayv, false); break;

                    case Value.Type.MAT2_T_ARRAY:   shader.SetMat2Array(key, (float[])val.InnerVal.arrayv, true); break;

                    case Value.Type.MAT3_ARRAY:             shader.SetMat3Array(key, (float[])val.InnerVal.arrayv, false); break;

                    case Value.Type.MAT3_T_ARRAY:   shader.SetMat3Array(key, (float[])val.InnerVal.arrayv, true); break;

                    case Value.Type.MAT4_ARRAY:             shader.SetMat4Array(key, (float[])val.InnerVal.arrayv, false); break;

                    case Value.Type.MAT4_T_ARRAY:   shader.SetMat4Array(key, (float[])val.InnerVal.arrayv, true); break;

                    default: break;
                    }
                }
            }