void DoBlit(IList <BlitInfo> blitInfos, int startIndex)
        {
            int usedSlots = Mathf.Min(blitInfos.Count - startIndex, k_TextureSlotCount);
            int stopIndex = startIndex + usedSlots;

            // Update the properties
            for (int blitIndex = startIndex, slotIndex = 0; blitIndex < stopIndex; ++blitIndex, ++slotIndex)
            {
                var texture = blitInfos[blitIndex].src;
                if (texture != null)
                {
                    m_Properties.SetTexture(k_TextureIds[slotIndex], texture);
                }
            }
            Utility.SetPropertyBlock(m_Properties);

            // Draw
            GL.Begin(GL.QUADS);
            for (int blitIndex = startIndex, slotIndex = 0; blitIndex < stopIndex; ++blitIndex, ++slotIndex)
            {
                BlitInfo current = blitInfos[blitIndex];

                float srcTexelWidth  = 1f / current.src.width;
                float srcTexelHeight = 1f / current.src.height;

                // Destination coordinates (in integer pixels).
                float dstLeft   = current.dstPos.x - current.border;
                float dstBottom = current.dstPos.y - current.border;
                float dstRight  = current.dstPos.x + current.srcRect.width + current.border;
                float dstTop    = current.dstPos.y + current.srcRect.height + current.border;

                // Source coordinates (normalized 0..1).
                float srcLeft   = (current.srcRect.x - current.border) * srcTexelWidth;
                float srcBottom = (current.srcRect.y - current.border) * srcTexelHeight;
                float srcRight  = (current.srcRect.xMax + current.border) * srcTexelWidth;
                float srcTop    = (current.srcRect.yMax + current.border) * srcTexelHeight;

                // Bottom left
                GL.Color(current.tint);
                GL.TexCoord3(srcLeft, srcBottom, slotIndex);
                GL.Vertex3(dstLeft, dstBottom, 0.0f);

                // Top left
                GL.Color(current.tint);
                GL.TexCoord3(srcLeft, srcTop, slotIndex);
                GL.Vertex3(dstLeft, dstTop, 0.0f);

                // Top right
                GL.Color(current.tint);
                GL.TexCoord3(srcRight, srcTop, slotIndex);
                GL.Vertex3(dstRight, dstTop, 0.0f);

                // Bottom right
                GL.Color(current.tint);
                GL.TexCoord3(srcRight, srcBottom, slotIndex);
                GL.Vertex3(dstRight, dstBottom, 0.0f);
            }

            GL.End();
        }
Example #2
0
        private void DoBlit(IList <BlitInfo> blitInfos, int startIndex)
        {
            int stopIndex = Mathf.Min(startIndex + k_TextureSlotCount, blitInfos.Count);

            // Bind and update the material.
            for (int blitIndex = startIndex, slotIndex = 0; blitIndex < stopIndex; ++blitIndex, ++slotIndex)
            {
                var texture = blitInfos[blitIndex].src;
                if (texture != null)
                {
                    m_BlitMaterial.SetTexture(k_TextureIds[slotIndex], texture);
                }
            }

            // Draw.
            m_BlitMaterial.SetPass(0);
            GL.Begin(GL.QUADS);
            for (int blitIndex = startIndex, slotIndex = 0; blitIndex < stopIndex; ++blitIndex, ++slotIndex)
            {
                BlitInfo current = blitInfos[blitIndex];
                // Pixel offset for the border in the destination texture:
                float borderDstOffset = current.addBorder ? 1 : 0;

                // UV offset used to create the border when reading the texture.
                float borderSrcWidth  = borderDstOffset / current.src.width;
                float borderSrcHeight = borderDstOffset / current.src.height;

                // Destination coordinates.
                float dstLeft   = current.x - borderDstOffset;
                float dstBottom = current.y - borderDstOffset;
                float dstRight  = current.x + current.src.width + borderDstOffset;
                float dstTop    = current.y + current.src.height + borderDstOffset;

                // Source coordinates.
                float srcLeft   = 0 - borderSrcWidth;
                float srcBottom = 0 - borderSrcHeight;
                float srcRight  = 1 + borderSrcWidth;
                float srcTop    = 1 + borderSrcHeight;

                // Bottom left
                GL.TexCoord3(srcLeft, srcBottom, slotIndex);
                GL.Vertex3(dstLeft, dstBottom, 0.0f);

                // Top left
                GL.TexCoord3(srcLeft, srcTop, slotIndex);
                GL.Vertex3(dstLeft, dstTop, 0.0f);

                // Top right
                GL.TexCoord3(srcRight, srcTop, slotIndex);
                GL.Vertex3(dstRight, dstTop, 0.0f);

                // Bottom right
                GL.TexCoord3(srcRight, srcBottom, slotIndex);
                GL.Vertex3(dstRight, dstBottom, 0.0f);
            }
            GL.End();
        }
Example #3
0
 /// <param name="x">Distance between the left of the atlas and the left boundary of the texture.</param>
 /// <param name="y">Distance between the bottom of the atlas and the bottom boundary of the texture.</param>
 /// <param name="addBorder">Blit a border using the texture wrap mode.</param>
 private void BlitSingle(Texture src, RenderTexture dst, int x, int y, bool addBorder)
 {
     m_SingleBlit[0] = new BlitInfo {
         src = src, x = x, y = y, addBorder = addBorder
     };
     BeginBlit(dst);
     DoBlit(m_SingleBlit, 0);
     EndBlit();
 }
        void DoBlit(IList <BlitInfo> blitInfos, int startIndex)
        {
            int stopIndex = Mathf.Min(startIndex + k_TextureSlotCount, blitInfos.Count);

            // Bind and update the material.
            for (int blitIndex = startIndex, slotIndex = 0; blitIndex < stopIndex; ++blitIndex, ++slotIndex)
            {
                var texture = blitInfos[blitIndex].src;
                if (texture != null)
                {
                    m_BlitMaterial.SetTexture(k_TextureIds[slotIndex], texture);
                }
            }

            // Draw.
            m_BlitMaterial.SetPass(0);
            GL.Begin(GL.QUADS);
            for (int blitIndex = startIndex, slotIndex = 0; blitIndex < stopIndex; ++blitIndex, ++slotIndex)
            {
                BlitInfo current = blitInfos[blitIndex];

                float srcTexelWidth  = 1f / current.src.width;
                float srcTexelHeight = 1f / current.src.height;

                // Destination coordinates (in integer pixels).
                float dstLeft   = current.dstPos.x - current.border;
                float dstBottom = current.dstPos.y - current.border;
                float dstRight  = current.dstPos.x + current.srcRect.width + current.border;
                float dstTop    = current.dstPos.y + current.srcRect.height + current.border;

                // Source coordinates (normalized 0..1).
                float srcLeft   = (current.srcRect.x - current.border) * srcTexelWidth;
                float srcBottom = (current.srcRect.y - current.border) * srcTexelHeight;
                float srcRight  = (current.srcRect.xMax + current.border) * srcTexelWidth;
                float srcTop    = (current.srcRect.yMax + current.border) * srcTexelHeight;

                // Bottom left
                GL.TexCoord3(srcLeft, srcBottom, slotIndex);
                GL.Vertex3(dstLeft, dstBottom, 0.0f);

                // Top left
                GL.TexCoord3(srcLeft, srcTop, slotIndex);
                GL.Vertex3(dstLeft, dstTop, 0.0f);

                // Top right
                GL.TexCoord3(srcRight, srcTop, slotIndex);
                GL.Vertex3(dstRight, dstTop, 0.0f);

                // Bottom right
                GL.TexCoord3(srcRight, srcBottom, slotIndex);
                GL.Vertex3(dstRight, dstBottom, 0.0f);
            }

            GL.End();
        }
        public void BlitOneNow(RenderTexture dst, Texture src, RectInt srcRect, Vector2Int dstPos, bool addBorder, Color tint)
        {
            if (disposed)
            {
                DisposeHelper.NotifyDisposedUsed(this);
                return;
            }

            m_SingleBlit[0] = new BlitInfo {
                src = src, srcRect = srcRect, dstPos = dstPos, border = addBorder ? 1 : 0, tint = tint
            };
            BeginBlit(dst);
            DoBlit(m_SingleBlit, 0);
            EndBlit();
        }