Exemplo n.º 1
0
        public void LoadSubData(IntPtr offset, IntPtr data, int size)
        {
            if (size < 0)
            {
                throw new ArgumentException("Size cannot be less than zero.");
            }
            if (this.bufferSize == 0)
            {
                throw new InvalidOperationException(string.Format(
                                                        "Cannot update {0}, because its storage was not initialized yet.",
                                                        typeof(NativeGraphicsBuffer).Name));
            }
            if ((uint)offset + size > this.bufferSize)
            {
                throw new ArgumentException(string.Format(
                                                "Cannot update {0} with offset {1} and size {2}, as this exceeds the internal " +
                                                "storage size {3}.",
                                                typeof(NativeGraphicsBuffer).Name,
                                                offset,
                                                size,
                                                this.bufferSize));
            }

            NativeGraphicsBuffer prevBound = GetBound(this.type);

            Bind(this.type, this);

            BufferTarget target = ToOpenTKBufferType(this.type);

            GL.BufferSubData(target, offset, size, data);

            Bind(this.type, prevBound);
        }
Exemplo n.º 2
0
        public static void Bind(GraphicsBufferType type, NativeGraphicsBuffer buffer)
        {
            if (GetBound(type) == buffer)
            {
                return;
            }
            SetBound(type, buffer);

            BufferTarget target = ToOpenTKBufferType(type);

            GL.BindBuffer(target, buffer != null ? buffer.Handle : 0);
        }
Exemplo n.º 3
0
 private static void SetBound(GraphicsBufferType type, NativeGraphicsBuffer buffer)
 {
     if (type == GraphicsBufferType.Vertex)
     {
         boundVertex = buffer;
     }
     else if (type == GraphicsBufferType.Index)
     {
         boundIndex = buffer;
     }
     else
     {
         return;
     }
 }
Exemplo n.º 4
0
        public void SetupEmpty(int size)
        {
            if (size < 0)
            {
                throw new ArgumentException("Size cannot be less than zero.");
            }

            NativeGraphicsBuffer prevBound = GetBound(this.type);

            Bind(this.type, this);

            BufferTarget target = ToOpenTKBufferType(this.type);

            GL.BufferData(target, size, IntPtr.Zero, BufferUsageHint.StreamDraw);

            this.bufferSize = size;

            Bind(this.type, prevBound);
        }
Exemplo n.º 5
0
        void IGraphicsBackend.Render(IReadOnlyList <DrawBatch> batches)
        {
            if (batches.Count == 0)
            {
                return;
            }

            this.RetrieveActiveShaders(batches);
            this.SetupSharedParameters(this.renderOptions.ShaderParameters);

            int       drawCalls    = 0;
            DrawBatch lastRendered = null;

            for (int i = 0; i < batches.Count; i++)
            {
                DrawBatch         batch      = batches[i];
                VertexDeclaration vertexType = batch.VertexBuffer.VertexType;

                // Bind the vertex buffer we'll use. Note that this needs to be done
                // before setting up any vertex format state.
                NativeGraphicsBuffer vertexBuffer = batch.VertexBuffer.NativeVertex as NativeGraphicsBuffer;
                NativeGraphicsBuffer.Bind(GraphicsBufferType.Vertex, vertexBuffer);

                bool first        = (i == 0);
                bool sameMaterial =
                    lastRendered != null &&
                    lastRendered.Material.Equals(batch.Material);

                // Setup vertex bindings. Note that the setup differs based on the
                // materials shader, so material changes can be vertex binding changes.
                if (lastRendered != null)
                {
                    this.FinishVertexFormat(lastRendered.Material, lastRendered.VertexBuffer.VertexType);
                }
                this.SetupVertexFormat(batch.Material, vertexType);

                // Setup material when changed.
                if (!sameMaterial)
                {
                    this.SetupMaterial(
                        batch.Material,
                        lastRendered != null ? lastRendered.Material : null);
                }

                // Draw the current batch
                this.DrawVertexBatch(
                    batch.VertexBuffer,
                    batch.VertexRanges,
                    batch.VertexMode);

                drawCalls++;
                lastRendered = batch;
            }

            // Cleanup after rendering
            NativeGraphicsBuffer.Bind(GraphicsBufferType.Vertex, null);
            NativeGraphicsBuffer.Bind(GraphicsBufferType.Index, null);
            if (lastRendered != null)
            {
                this.FinishMaterial(lastRendered.Material);
                this.FinishVertexFormat(lastRendered.Material, lastRendered.VertexBuffer.VertexType);
            }

            if (this.renderStats != null)
            {
                this.renderStats.DrawCalls += drawCalls;
            }

            this.FinishSharedParameters();
        }