示例#1
0
        /// <summary>
        /// Ends the batching
        /// </summary>
        public void EndDraw()
        {
            if (!beginEndPair)
            {
                return;
            }

            beginEndPair = false;

            deviceBuffer.Bind();

            // if we have lighted polygons to draw
            if (litPolygonBuffer.Count > 0)
            {
                litColorShader.Start();
                litColorShader.SetViewProjectionMatrix(currentViewProjectionMatrix);
                litColorShader.SpecifyAttributes(PrimitiveVertex.SizeInBytes);

                deviceBuffer.Data(litPolygonBuffer, litPolygonBuffer.Count * PrimitiveVertex.SizeInBytes, BufferUsageHint.StreamDraw);
                GL.DrawArrays(PrimitiveType.Triangles, 0, litPolygonBuffer.Count);
            }

            // start initializing color shader
            colorShader.Start();
            colorShader.SetViewProjectionMatrix(currentViewProjectionMatrix);
            colorShader.SpecifyAttributes(PrimitiveVertex.SizeInBytes);

            // if we have polygons to draw
            if (polygonBuffer.Count > 0)
            {
                deviceBuffer.Data(polygonBuffer, polygonBuffer.Count * PrimitiveVertex.SizeInBytes, BufferUsageHint.StreamDraw);
                GL.DrawArrays(PrimitiveType.Triangles, 0, polygonBuffer.Count);
            }

            // if we have lines to draw
            if (lineBuffer.Count > 0)
            {
                deviceBuffer.Data(lineBuffer, lineBuffer.Count * PrimitiveVertex.SizeInBytes, BufferUsageHint.StreamDraw);
                GL.DrawArrays(PrimitiveType.Lines, 0, lineBuffer.Count);
            }

            // if we have textured polygons to draw
            if (texturedPolygonBuffer.Count > 0)
            {
                // setup texture shader
                litTexturerShader.Start();
                litTexturerShader.SetViewProjectionMatrix(currentViewProjectionMatrix);
//                litTexturerShader.SetTextureUnit(0);
                litTexturerShader.SpecifyAttributes(PrimitiveVertex.SizeInBytes);

                foreach (var keyValuePair in texturedPolygonBuffer)
                {
                    // bind texture
                    Texture2D texture = keyValuePair.Key;
                    texture.Bind();

                    // draw textures
                    List <PrimitiveVertex> vertexList = keyValuePair.Value;
                    deviceBuffer.Data(vertexList, vertexList.Count * PrimitiveVertex.SizeInBytes, BufferUsageHint.StreamDraw);
                    GL.DrawArrays(PrimitiveType.Triangles, 0, vertexList.Count);
                }
            }
        }