Пример #1
0
        public void RenderCustom(RenderState rs, Shader shdr, ShaderAction customAction, ref RenderCommand cmd)
        {
            FlushCommands(rs);
            //Setup shader default state
            rs.Cull      = false;
            rs.BlendMode = BlendMode.Normal;
            var splt = new SplitInt()
            {
                I = shdr.UserTag
            };

            if (shdr.UserTag == 0)
            {
                splt.A       = (short)shdr.GetLocation("View");
                splt.B       = (short)shdr.GetLocation("ViewProjection");
                shdr.UserTag = splt.I;
            }
            var view = camera.View;

            shdr.SetMatrix(splt.A, ref view);
            var vp = camera.ViewProjection;

            shdr.SetMatrix(splt.B, ref vp);
            //User-defined
            customAction(shdr, rs, ref cmd);
            //Draw
            vboBasic.Draw(PrimitiveTypes.TriangleList, 0, lastIndexBasic, 2);
            //Set stuff
            rs.Cull         = true;
            lastDatHash     = -1;
            lastIndexBasic += 6;
        }
        void Flush()
        {
            if (vertexCount == 0 || primitiveCount == 0)
            {
                return;
            }
            rs.Cull         = false;
            rs.BlendMode    = currentMode;
            rs.DepthEnabled = false;
            currentTexture.BindTo(0);
            if (currentTexture.Format == SurfaceFormat.R8)
            {
                imgShader.SetFloat(blendLocation, 1f);
            }
            else
            {
                imgShader.SetFloat(blendLocation, 0f);
            }
            var verts = new Vertex2D[vertexCount];

            for (int i = 0; i < vertexCount; i++)
            {
                verts[i] = vertices[i];
            }
            vbo.EndStreaming(vertexCount);
            vbo.Draw(PrimitiveTypes.TriangleList, primitiveCount);
            vertices       = (Vertex2D *)vbo.BeginStreaming();
            vertexCount    = 0;
            primitiveCount = 0;
            currentTexture = null;
            rs.Cull        = true;
        }
Пример #3
0
 public void AddCommand(RenderMaterial material, MaterialAnim anim, WorldMatrixHandle world, Lighting lights, VertexBuffer buffer, PrimitiveTypes primitive, int baseVertex, int start, int count, int layer, float z = 0, DfmSkinning skinning = null)
 {
     if (material.IsTransparent)
     {
         Transparents[transparentCommand++] = new RenderCommand()
         {
             Source       = material,
             MaterialAnim = anim,
             Lights       = lights,
             Buffer       = buffer,
             BaseVertex   = baseVertex,
             Start        = start,
             Count        = count,
             Primitive    = primitive,
             CmdType      = RenderCmdType.Material,
             World        = world,
             SortLayer    = layer,
             Z            = z
         };
     }
     else
     {
         if (skinning != null)
         {
             material.Bones        = BonesBuffer;
             material.BufferOffset = skinning.BufferOffset;
         }
         else
         {
             material.Bones = null;
         }
         material.MaterialAnim = anim;
         material.World        = world;
         material.Use(rstate, buffer.VertexType, ref lights);
         buffer.Draw(primitive, baseVertex, start, count);
         if (material.DoubleSided)
         {
             material.FlipNormals = true;
             material.UpdateFlipNormals();
             rstate.CullFace = CullFaces.Front;
             buffer.Draw(primitive, baseVertex, start, count);
             rstate.CullFace      = CullFaces.Back;
             material.FlipNormals = false;
         }
     }
 }
        public void Render()
        {
            if (lineVertices == 0)
            {
                return;
            }
            rstate.Cull         = false;
            rstate.DepthEnabled = false;
            var vp = camera.ViewProjection;

            shader.SetViewProjection(ref vp);
            shader.UseProgram();
            linebuffer.SetData(lines, lineVertices);
            linebuffer.Draw(PrimitiveTypes.LineList, lineVertices / 2);
            rstate.Cull         = true;
            rstate.DepthEnabled = true;
        }
Пример #5
0
 public void AddCommand(RenderMaterial material, MaterialAnim anim, WorldMatrixHandle world, Lighting lights, VertexBuffer buffer, PrimitiveTypes primitive, int baseVertex, int start, int count, int layer, float z = 0, DfmSkinning skinning = null)
 {
     if (material.IsTransparent)
     {
         Transparents[transparentCommand++] = new RenderCommand()
         {
             Key          = RenderCommand.MakeKey(RenderType.Transparent, material.Key, layer, z, 0),
             Source       = material,
             MaterialAnim = anim,
             Lights       = lights,
             Buffer       = buffer,
             BaseVertex   = baseVertex,
             Start        = start,
             Count        = count,
             Primitive    = primitive,
             CmdType      = RenderCmdType.Material,
             World        = world,
         };
     }
     else
     {
         if (skinning != null)
         {
             material.Bones        = BonesBuffer;
             material.BufferOffset = skinning.BufferOffset;
         }
         else
         {
             material.Bones = null;
         }
         material.MaterialAnim = anim;
         material.World        = world;
         material.Use(rstate, buffer.VertexType, ref lights);
         if (material.DoubleSided)
         {
             rstate.Cull = false;
         }
         buffer.Draw(primitive, baseVertex, start, count);
         if (material.DoubleSided)
         {
             rstate.Cull = true;
         }
     }
 }
Пример #6
0
        void Flush()
        {
            if (vertexCount == 0 || primitiveCount == 0)
            {
                return;
            }
            rs.Cull         = false;
            rs.BlendMode    = currentMode;
            rs.DepthEnabled = false;
            currentTexture.BindTo(0);
            currentShader.UseProgram();
            vbo.SetData(vertices, vertexCount);
            vbo.Draw(PrimitiveTypes.TriangleList, primitiveCount);

            vertexCount    = 0;
            primitiveCount = 0;
            currentTexture = null;
            rs.Cull        = true;
        }
Пример #7
0
        void DrawCommands(RenderContext rs, int start, int count)
        {
            shaderBasic.UseProgram();
            rs.Cull = false;

            rs.BlendMode = rendat[datindex].BlendMode;
            if (_frameStart)
            {
                var v  = camera.View;
                var vp = camera.ViewProjection;
                shaderBasic.SetView(ref v);
                shaderBasic.SetViewProjection(ref vp);
                _frameStart = false;
            }

            rendat[datindex].Texture.BindTo(0);
            vboBasic.Draw(PrimitiveTypes.TriangleList, 0, start, count / 3);
            rs.Cull     = true;
            lastDatHash = -1;
        }
Пример #8
0
        public void FlushCommands(RenderState rs)
        {
            FillIbo();
            if (indexCountBasic == 0 && indexCountRect == 0)
            {
                lastDatHash = -1;
                return;
            }
            rs.Cull      = false;
            rs.BlendMode = rendat[datindex].BlendMode;
            var rect = rendat[datindex].RenderKind == RenderKind.Rect;

            if (_frameStart)
            {
                var v  = camera.View;
                var vp = camera.ViewProjection;
                shaderBasic.SetView(ref v);
                shaderBasic.SetViewProjection(ref vp);
                shaderRect.SetView(ref v);
                shaderRect.SetViewProjection(ref vp);
                _frameStart = false;
            }
            rendat[datindex].Texture.BindTo(0);
            (rect ? shaderRect : shaderBasic).UseProgram();
            if (rect)
            {
                vboRect.Draw(PrimitiveTypes.TriangleList, 0, lastIndexRect, indexCountRect / 3);
                lastIndexRect += indexCountRect;
                indexCountRect = 0;
            }
            else
            {
                vboBasic.Draw(PrimitiveTypes.TriangleList, 0, lastIndexBasic, indexCountBasic / 3);
                lastIndexBasic += indexCountBasic;
                indexCountBasic = 0;
            }
            rs.Cull     = true;
            lastDatHash = -1;
        }
Пример #9
0
 public unsafe void Run(RenderState state)
 {
     if (CmdType == RenderCmdType.Material || CmdType == RenderCmdType.MaterialFade)
     {
         var Material = (RenderMaterial)Source;
         if (Material == null)
         {
             return;
         }
         Material.MaterialAnim = MaterialAnim;
         Material.World        = World;
         if (CmdType == RenderCmdType.MaterialFade)
         {
             Material.Fade = true;
             var fn = BaseVertex;
             var ff = Index;
             Material.FadeNear = *(float *)(&fn);
             Material.FadeFar  = *(float *)(&ff);
         }
         if (Material.DisableCull)
         {
             state.Cull = false;
         }
         Material.Use(state, Buffer.VertexType, ref Lights);
         if ((CmdType != RenderCmdType.MaterialFade) && BaseVertex != -1)
         {
             Buffer.Draw(Primitive, BaseVertex, Start, Count);
         }
         else
         {
             Buffer.Draw(Primitive, Count);
         }
         if (Material.DoubleSided)
         {
             Material.FlipNormals = true;
             Material.UpdateFlipNormals();
             state.CullFace = CullFaces.Front;
             if ((CmdType != RenderCmdType.MaterialFade) && BaseVertex != -1)
             {
                 Buffer.Draw(Primitive, BaseVertex, Start, Count);
             }
             else
             {
                 Buffer.Draw(Primitive, Count);
             }
             state.CullFace       = CullFaces.Back;
             Material.FlipNormals = false;
         }
         if (CmdType == RenderCmdType.MaterialFade)
         {
             Material.Fade = false;
         }
         if (Material.DisableCull)
         {
             state.Cull = true;
         }
     }
     else if (CmdType == RenderCmdType.Shader)
     {
         var Shader = (Shader)Source;
         ShaderSetup(Shader, state, ref this);
         Shader.UseProgram();
         if (BaseVertex != -1)
         {
             Buffer.Draw(Primitive, BaseVertex, Start, Count);
         }
         else
         {
             Buffer.Draw(Primitive, Start, Count);
         }
         if (Cleanup != null)
         {
             ((Action <RenderState>)Cleanup)(state);
         }
     }
     else if (CmdType == RenderCmdType.Billboard)
     {
         var Billboards = (Billboards)Source;
         Billboards.Render(Index, Hash, state);
     }
 }