public void DrawBatch20(SpriteSortMode sortMode) { // nothing to do if (_batchItemList.Count == 0) { return; } // sort the batch items switch (sortMode) { case SpriteSortMode.Texture: _batchItemList.Sort(CompareTexture); break; case SpriteSortMode.FrontToBack: _batchItemList.Sort(CompareDepth); break; case SpriteSortMode.BackToFront: _batchItemList.Sort(CompareReverseDepth); break; } // make sure an old draw isn't still going on. // cross fingers, commenting this out!! //GL20.Flush(); GL20.EnableVertexAttribArray(attributePosition); GL20.EnableVertexAttribArray(attributeTexCoord); int size = VertexPosition2ColorTexture.GetSize(); GL20.VertexAttribPointer(attributePosition, 2, All20.Float, false, size, _vertexHandle.AddrOfPinnedObject()); GL20.VertexAttribPointer(attributeTexCoord, 2, All20.Float, false, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint)))); // GL11.VertexPointer(2,All11.Float,size,_vertexHandle.AddrOfPinnedObject() ); // GL11.ColorPointer(4, All11.UnsignedByte,size,(IntPtr)((uint)_vertexHandle.AddrOfPinnedObject()+(uint)(sizeof(float)*2))); // GL11.TexCoordPointer(2, All11.Float,size,(IntPtr)((uint)_vertexHandle.AddrOfPinnedObject()+(uint)(sizeof(float)*2+sizeof(uint))) ); // setup the vertexArray array int startIndex = 0; int index = 0; int texID = -1; Color lastTint = new Color(0.0f, 0.0f, 0.0f, 0.0f); // make sure the vertexArray has enough space if (_batchItemList.Count * 4 > _vertexArray.Length) { ExpandVertexArray(_batchItemList.Count); } foreach (SpriteBatchItem item in _batchItemList) { //Tint Color Vector4 vtint = item.Tint.ToVector4(); vtint /= 255; // GL20.VertexAttrib4(attributeTint,vtint.X, vtint.Y, vtint.Z, vtint.W); // if the texture changed, we need to flush and bind the new texture if (item.TextureID != texID || item.Tint != lastTint) { FlushVertexArray20(startIndex, index); startIndex = index; texID = item.TextureID; lastTint = item.Tint; GL20.ActiveTexture(All20.Texture0); GL20.BindTexture(All20.Texture2D, texID); GL20.Uniform1(texID, 0); GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W); } // store the SpriteBatchItem data in our vertexArray _vertexArray[index++] = item.vertexTL; _vertexArray[index++] = item.vertexTR; _vertexArray[index++] = item.vertexBL; _vertexArray[index++] = item.vertexBR; _freeBatchItemQueue.Enqueue(item); } // flush the remaining vertexArray data FlushVertexArray20(startIndex, index); _batchItemList.Clear(); }
public void DrawBatchGL20(SpriteSortMode sortMode) { // nothing to do if (_batchItemList.Count == 0) { return; } // sort the batch items switch (sortMode) { case SpriteSortMode.Texture: //_batchItemList.Sort( CompareTexture ); throw new NotSupportedException(); case SpriteSortMode.FrontToBack: //_batchItemList.Sort ( CompareDepth ); throw new NotSupportedException(); case SpriteSortMode.BackToFront: //_batchItemList.Sort ( CompareReverseDepth ); throw new NotSupportedException(); } GL20.EnableVertexAttribArray(attributePosition); GL20.EnableVertexAttribArray(attributeTexCoord); // make sure the vertexArray has enough space if (_batchItemList.Count * 4 > _index.Length) { ExpandIndexArray(_batchItemList.Count); } LinkVertexArray(); int size = VertexPosition2ColorTexture.GetSize(); GL20.VertexAttribPointer(attributePosition, 2, ALL20.Float, false, size, _vertexHandle.AddrOfPinnedObject()); GL20.VertexAttribPointer(attributeTexCoord, 2, ALL20.Float, false, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint)))); // setup the vertexArray array int startIndex = 0; int index = 0; int texID = -1; Color lastTint = new Color(0.0f, 0.0f, 0.0f, 0.0f); foreach (SpriteBatchItem item in _batchItemList) { //Tint Color Vector4 vtint = item.Tint.ToVector4(); //vtint /= 255; //GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W); // if the texture changed, we need to flush and bind the new texture if (item.TextureID != texID || item.Tint != lastTint) { FlushVertexArrayGL20(startIndex, index); startIndex = index; texID = item.TextureID; lastTint = item.Tint; GL20.ActiveTexture(ALL20.Texture0); GL20.BindTexture(ALL20.Texture2D, texID); GL20.Uniform1(texID, 0); GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W); } index += 4; } // flush the remaining vertexArray data FlushVertexArrayGL20(startIndex, index); _batchItemList.Clear(); _vertexArray.Clear(); }