Exemplo n.º 1
0
        public void ApplyParams(MaterialParams p, Transform world)
        {
            BindAll(BuiltInParams.World, world);
            foreach (var x in p.Params)
            {
                string name  = x.Key;
                var    param = x.Value;

                switch (param.Type)
                {
                case GLType.Int: BindAll(name, param.Get <int>()); break;

                case GLType.Float: BindAll(name, param.Get <float>()); break;

                case GLType.FloatMat4: BindAll(name, param.Get <Matrix4x4>()); break;

                case GLType.FloatVec2: BindAll(name, param.Get <Vector2>()); break;

                case GLType.FloatVec3: BindAll(name, param.Get <Vector3>()); break;

                case GLType.FloatVec4: BindAll(name, param.Get <Vector4>()); break;

                case GLType.Sampler2D:
                    if (!m_textureIDs.TryGetValue(name, out uint unit))
                    {
                        // TODO(local): error!!!
                        break;
                    }

                    param.Get <Texture>().Bind(unit);
                    BindAll(name, (int)unit);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public void Bind(RenderState state, MaterialParams p)
        {
            BindAll(BuiltInParams.Projection, state.ProjectionMatrix);
            BindAll(BuiltInParams.Camera, state.CameraMatrix);

            ApplyParams(p, state.WorldTransform);
            BindToContext();
        }
Exemplo n.º 3
0
        public MaterialParams Copy()
        {
            var result = new MaterialParams();

            foreach (var entry in Params)
            {
                result.Params[entry.Key] = entry.Value.Copy();
            }
            return(result);
        }
Exemplo n.º 4
0
        public virtual void Draw(Transform world, Mesh mesh, Material mat, MaterialParams p)
        {
            var sdc = new SimpleDrawCall()
            {
                Mesh           = mesh,
                Material       = mat,
                Params         = p,
                WorldTransform = world,
                Scissor        = Rect.EmptyScissor,
            };

            m_orderedCommands.Add(sdc);
        }
Exemplo n.º 5
0
        internal RenderBatcher2D(RenderBatch2D parent, int vertexCount = 0)
        {
            if (vertexCount < 0 || vertexCount > MaxVertexCount)
            {
                throw new ArgumentOutOfRangeException($"{nameof(vertexCount)} must be in the range [0,{MaxVertexCount})");
            }
            if (vertexCount == 0)
            {
                vertexCount = MaxVertexCount;
            }

            m_batch = parent;

            m_mesh     = new Mesh();
            m_material = parent.Resources.AquireMaterial("materials/renderBatch2D");
            m_params   = new MaterialParams();

            m_indices  = new ushort[vertexCount];
            m_vertices = new VertexRB2D[vertexCount];
        }
Exemplo n.º 6
0
        internal void Begin()
        {
            m_vertexCount = 0;
            m_indexCount  = 0;

            m_world      = Transform.Identity;
            m_projection = (Transform)Matrix4x4.CreateOrthographicOffCenter(0, Window.Width, Window.Height, 0, -10, 10);
            m_camera     = Transform.Identity;

            m_texture = null;

            m_fillKind    = SolidFillKind;
            m_vertexColor = Vector4.One;

            m_transform = Transform.Identity;
            m_scissor   = null;
            m_transformations.Clear();
            m_savedTransformIndices.Clear();
            m_savedScissors.Clear();

            m_params = new MaterialParams();
        }