Example #1
0
        /// <summary>
        /// Renders the batch with custom alpha and blend mode values, as well as a custom mvp matrix.
        /// </summary>
        public void Render(Matrix matrix, float alpha, uint blendMode)
        {
            if (_numQuads == 0)
            {
                return;
            }

            if (_syncRequired)
            {
                SyncBuffers(alpha);
            }

            if (blendMode == Display.BlendMode.AUTO)
            {
                throw new InvalidOperationException("Cannot render object with blend mode AUTO");
            }
            bool useTinting = _tinted || alpha != 1.0f;

            _baseEffect.PrepareToDraw(matrix, _premultipliedAlpha, alpha, useTinting, _texture);

            Display.BlendMode.ApplyBlendFactors(blendMode, _premultipliedAlpha);

            int attribPosition = _baseEffect.AttribPosition;

            GL.EnableVertexAttribArray(attribPosition);

            int attribColor = _baseEffect.AttribColor;

            if (useTinting)
            {
                GL.EnableVertexAttribArray(attribColor);
            }

            int attribTexCoords = _baseEffect.AttribTexCoords;

            if (_texture != null)
            {
                GL.EnableVertexAttribArray(attribTexCoords);
            }

            GL.BindBuffer(BufferTarget.ArrayBuffer, _vertexBufferName);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, _indexBufferName);

            GL.VertexAttribPointer(attribPosition, 2, VertexAttribPointerType.Float, false, Vertex.SIZE, (IntPtr)Vertex.POSITION_OFFSET);

            if (_texture != null)
            {
                GL.VertexAttribPointer(attribTexCoords, 2, VertexAttribPointerType.Float, false, Vertex.SIZE, (IntPtr)Vertex.TEXTURE_OFFSET);
            }

            if (useTinting)
            {
                GL.BindBuffer(BufferTarget.ArrayBuffer, _vertexColorsBufferName);
                GL.VertexAttribPointer(attribColor, 4, VertexAttribPointerType.UnsignedByte, true, sizeof(float), (IntPtr)0);
            }

            int numIndices = _numQuads * INDICES_PER_QUAD;

            GL.DrawElements(BeginMode.Triangles, numIndices, DrawElementsType.UnsignedShort, IntPtr.Zero);
//			GL.DrawElements (All.TriangleStrip, numIndices, All.UnsignedShort, IntPtr.Zero);
        }