コード例 #1
0
 public bool Render(Shader shader, int submesh)
 {
     if (d3dmesh == null) return false;
     if (d3dmesh.Iteration < Iteration) return false;
     d3dmesh.SetSubmesh(submesh);
     d3dmesh.Render(shader);
     return true;
 }
コード例 #2
0
 private InputLayout GetInputLayout(Shader shader)
 {
     if (shadermap.ContainsKey(shader)) return shadermap[shader];
     var layout = shader.CreateLayout(inputelements);
     shadermap.Add(shader, layout);
     return layout;
 }
コード例 #3
0
        /// <summary>
        /// Binds the specified texture to the specified texture at the given variable name and slot
        /// </summary>
        /// <param name="shader"></param>
        /// <param name="uniform"></param>
        /// <param name="texture"></param>
        /// <param name="slot"></param>
        public void BindShaderTexture(Shader shader, string uniform, Texture2D texture)
        {
            // Get the view and bind it to the shader
            ShaderResourceView view = AcquireResourceView(texture);
            shader.SetVariable(uniform, view);

            // See if the view is already bound to a slot
            // Whilst we're at it, see if there's a free slot we can use, and search for slot with the lowest uses
            int freeslot = -1;
            int lowestuses = resourceviewslots[0].NumUses;
            int lowestusesidx = 0;
            for (int i = 0; i < MaxPixelShaderResourceViewSlots; i++)
                if (resourceviewslots[i].View == view)
                {
                    resourceviewslots[i].NumUses++;
                    return;
                }
                else if (resourceviewslots[i].View == null && freeslot == -1)
                    freeslot = i;
                else if (resourceviewslots[i].NumUses < lowestuses)
                {
                    lowestuses = resourceviewslots[i].NumUses;
                    lowestusesidx = i;
                }

            // If we got this far, we need to find a slot
            // If there is none free, select the one with the lowest uses
            freeslot = lowestusesidx;

            // Use it
            context.PixelShader.SetShaderResource(view, freeslot);
            resourceviewslots[freeslot].View = view;
            resourceviewslots[freeslot].NumUses = 1;
        }
コード例 #4
0
 public void Render(Shader shader)
 {
     InputLayout layout = GetInputLayout(shader);
     if (layout != CurrentInputLayout)
     {
         CurrentInputLayout = layout;
         context.InputAssembler.InputLayout = layout;
     }
     context.InputAssembler.PrimitiveTopology = Topology;
     if (bufferbinding != CurrentVertexBufferBinding)
     {
         CurrentVertexBufferBinding = bufferbinding;
         context.InputAssembler.SetVertexBuffers(0, bufferbinding);
     }
     if (ibIndices != CurrentIndexBuffer)
     {
         CurrentIndexBuffer = ibIndices;
         context.InputAssembler.SetIndexBuffer(ibIndices, indexformat, 0);
     }
     context.DrawIndexed(curindices, 0, 0);
 }
コード例 #5
0
        private Shader LoadShader(string name)
        {
            // Check the file exists
            string filename = string.Format("shaders/{0}.fx", name);
            if (!File.Exists(filename)) return null;

            // Load it
            string source = File.ReadAllText(filename);
            Console.WriteLine("Loading shader {0}...", name);
            Shader shader = new Shader(Owner.GetComponent<Renderer>().Device);
            shader.VertexFromString(source);
            shader.PixelFromString(source);
            if (source.Contains("GShader")) shader.GeometryFromString(source);
            shader.EffectFromString(source);

            // Return it
            return shader;
        }