Ejemplo n.º 1
0
        public static unsafe void End()
        {
            List<DrawItem> drawList = new List<DrawItem>();

            if (totalVertex == 0)
                return;

            IntPtr vertexData = vertexBuffer.Lock(0, totalVertex, true);

            if (vertexData == IntPtr.Zero)
                return;

            uint startVertex = 0;

            PositionColorUVVertex* vout = (PositionColorUVVertex*)vertexData;

            foreach (var layer in layerBatches)
            {
                foreach (var batch in layer.Value.Values)
                {
                    if (totalVertex + batch.VertexCount >= maxVertices)
                    {
                        throw new System.InvalidOperationException("Ran out of vertices");
                    }

                    if (batch.VertexCount == 0)
                        continue;

                    // faster blit possible?
                    for (uint i = 0; i < batch.VertexCount; i++, vout++)
                    {
                        *vout = batch.Vertices[i];
                    }

                    var item = new DrawItem();
                    item.Texture = batch.Texture;
                    item.StartVertex = startVertex;
                    item.VertexCount = batch.VertexCount;

                    startVertex += batch.VertexCount;
                    drawList.Add(item);

                }

            }

            vertexBuffer.Unlock();

            var renderer = AtomicNET.GetSubsystem<Renderer>();
            var graphics = AtomicNET.GetSubsystem<Graphics>();

            var view = renderer.GetViewport(0).View;
            var camera = renderer.GetViewport(0).Camera;

            if (view == null || camera == null)
                return;

            graphics.SetBlendMode(BlendMode.BLEND_ADDALPHA);
            graphics.SetCullMode(CullMode.CULL_NONE);
            graphics.SetFillMode(FillMode.FILL_SOLID);
            graphics.SetDepthTest(CompareMode.CMP_ALWAYS);

            graphics.SetShaders(vertexShader, pixelShader);

            view.SetCameraShaderParameters(camera);
            graphics.SetShaderParameter(ShaderParams.VSP_MODEL, Matrix3x4.IDENTITY);

            graphics.SetShaderParameter(ShaderParams.PSP_MATDIFFCOLOR, Color.White);

            graphics.SetVertexBuffer(vertexBuffer);

            foreach (var item in drawList)
            {
                graphics.SetTexture((int) TextureUnit.TU_DIFFUSE, item.Texture);
                graphics.Draw(PrimitiveType.TRIANGLE_LIST, item.StartVertex, item.VertexCount);
            }

            graphics.SetTexture(0, null);
        }
Ejemplo n.º 2
0
        unsafe public static void End()
        {
            List <DrawItem> drawList = new List <DrawItem>();


            if (totalVertex == 0)
            {
                return;
            }

            IntPtr vertexData = vertexBuffer.Lock(0, totalVertex, true);

            if (vertexData == IntPtr.Zero)
            {
                return;
            }

            uint startVertex = 0;

            PositionColorUVVertex *vout = (PositionColorUVVertex *)vertexData;

            foreach (var layer in layerBatches)
            {
                foreach (var batch in layer.Value.Values)
                {
                    if (totalVertex + batch.VertexCount >= maxVertices)
                    {
                        throw new System.InvalidOperationException("Ran out of vertices");
                    }

                    if (batch.VertexCount == 0)
                    {
                        continue;
                    }

                    // faster blit possible?
                    for (uint i = 0; i < batch.VertexCount; i++, vout++)
                    {
                        *vout = batch.Vertices[i];
                    }

                    var item = new DrawItem();
                    item.Texture     = batch.Texture;
                    item.StartVertex = startVertex;
                    item.VertexCount = batch.VertexCount;

                    startVertex += batch.VertexCount;
                    drawList.Add(item);
                }
            }


            vertexBuffer.Unlock();

            var renderer = AtomicNET.GetSubsystem <Renderer>();
            var graphics = AtomicNET.GetSubsystem <Graphics>();

            var view   = renderer.GetViewport(0).View;
            var camera = renderer.GetViewport(0).Camera;

            if (view == null || camera == null)
            {
                return;
            }

            graphics.SetBlendMode(BlendMode.BLEND_ADDALPHA);
            graphics.SetCullMode(CullMode.CULL_NONE);
            graphics.SetFillMode(FillMode.FILL_SOLID);
            graphics.SetDepthTest(CompareMode.CMP_ALWAYS);

            graphics.SetShaders(vertexShader, pixelShader);

            view.SetCameraShaderParameters(camera);
            graphics.SetShaderParameter(ShaderParams.VSP_MODEL, Matrix3x4.IDENTITY);

            graphics.SetShaderParameter(ShaderParams.PSP_MATDIFFCOLOR, Color.White);

            graphics.SetVertexBuffer(vertexBuffer);

            foreach (var item in drawList)
            {
                graphics.SetTexture((int)TextureUnit.TU_DIFFUSE, item.Texture);
                graphics.Draw(PrimitiveType.TRIANGLE_LIST, item.StartVertex, item.VertexCount);
            }

            graphics.SetTexture(0, null);
        }