public void Render(RenderQueue.Batch renderBatch) { var batch = (Batch)renderBatch; var entries = batch.Entries; if (entries.Count == 0) { return; } RenderHelpers.SetBlendMode(blendMode); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); currentEffect.Projection = Projection ?? CurrentContext.ActiveScreen.DefaultProjection; currentEffect.View = transform; currentEffect.Enable(); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferObjects[0]); GL.VertexAttribPointer(currentEffect.VertexAttribute, 2, VertexAttribPointerType.Float, false, Vertex2Color.GetSize(), 0); if (currentEffect.ColorAttribute.HasValue) { GL.VertexAttribPointer(currentEffect.ColorAttribute.Value, 4, VertexAttribPointerType.UnsignedByte, true, Vertex2Color.GetSize(), 2 * sizeof(float)); } for (int entryIndex = 0; entryIndex < entries.Count;) { var startingEntry = entries[entryIndex]; var mode = GetMode(startingEntry); int index = 0; AddEntry(startingEntry, ref index); for (int nextIndex = entryIndex + 1; nextIndex < entries.Count; ++nextIndex) { var nextEntry = entries[nextIndex]; if (GetMode(nextEntry) == mode) { AddEntry(nextEntry, ref index); entryIndex++; } else { break; } } if (index > 0) { GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(index * Vertex2Color.GetSize()), vertexStorage, BufferUsageHint.DynamicDraw); GL.DrawArrays(mode, 0, index); } entryIndex++; } entries.Clear(); currentEffect.Disable(); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); // This group is done, recycle it to the pool batchPool.Delete(batch); }
private void Render(RenderQueue.Batch renderBatch) { var batch = (Batch)renderBatch; var entries = batch.Entries; if (entries.Count > 0) { RenderHelpers.SetBlendMode(blendMode); GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.DepthTest); //GL.Viewport(graphicsDevice.Viewport.X, graphicsDevice.BackBufferSize.Y - graphicsDevice.Viewport.Y - graphicsDevice.Viewport.Height, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height); currentEffect.Projection = Projection ?? CurrentContext.ActiveScreen.DefaultProjection; currentEffect.View = transform; currentEffect.Enable(); for (int i = 0; i < entries.Count;) { int quadIndex = 0; BatchEntry firstEntry = entries[i]; Texture2D texture = firstEntry.Texture; if (AddEntry(ref firstEntry, quadIndex++) == 0) { Debug.WriteLine("Warning: out of QuadBatch capacity!"); break; } // Push in new quads until we reach a new texture int entryCount = 1; for (int j = i + 1; j < entries.Count; ++j) { BatchEntry futureEntry = entries[j]; if (futureEntry.Texture != texture) { break; } int added = AddEntry(ref futureEntry, quadIndex++); if (added == 0) { Debug.WriteLine("Warning: out of QuadBatch capacity!"); } entryCount += added; // If we're out of entry slots, do not increase entryCount } // Set texture GL.BindTexture(TextureTarget.Texture2D, texture.textureId); RenderHelpers.SetSamplers(textureSampling); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferObjects[0]); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(entryCount * 6 * Vertex2Tex2Color.GetSize()), quads, BufferUsageHint.DynamicDraw); //GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero, (IntPtr)(entryCount * 6 * Vertex2Tex2Color.GetSize()), quads); GL.BindBuffer(BufferTarget.ElementArrayBuffer, vertexBufferObjects[1]); if (currentEffect.ColorAttribute.HasValue) { GL.VertexAttribPointer(currentEffect.ColorAttribute.Value, 4, VertexAttribPointerType.UnsignedByte, true, Vertex2Tex2Color.GetSize(), sizeof(float) * 2); } GL.VertexAttribPointer(currentEffect.VertexAttribute, 2, VertexAttribPointerType.Float, false, Vertex2Tex2Color.GetSize(), 0); GL.VertexAttribPointer(currentEffect.TextureCoordinatesAttribute, 2, VertexAttribPointerType.Float, false, Vertex2Tex2Color.GetSize(), sizeof(float) * 2 + sizeof(byte) * 4); GL.DrawElements(BeginMode.Triangles, entryCount * 6, DrawElementsType.UnsignedShort, 0); i += entryCount; } entries.Clear(); currentEffect.Disable(); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); } // This group is done, recycle it to the pool batchPool.Delete(batch); }