Exemplo n.º 1
0
        /*
         * Quads are kept sorted by zOrder, and within zOrder, by Texture.  In this way, we will
         * minimized batches.
         */
        public void addQuadToRenderList(QuickGUIQuad q)
        {
            bool added = false;

            for (int it = 0; it < mRenderList.Count; it++)
            {
                QuickGUIQuad iq = mRenderList[it];
                // quad is already in the list! update quad instead
                if (iq.getID() == q.getID())
                {
                    updateQuadInRenderList(q);
                    added = true;
                    break;
                }

                // zOrders are the same, now we want to group by texture
                if (iq.getZOrder() == q.getZOrder())
                {
                    // iterate until texture name found, or end of zOrder grouping
                    while (!iq.getTextureName().Equals(iq.getTextureName()) && (iq.getZOrder() == q.getZOrder()) && (it < mRenderList.Count))
                    {
                        ++it;
                    }

                    // it is pointing to the end of the list, a quad with the same texture name, or a quad of another zOrder
                    mRenderList.Insert(it, q);
                    q._notifyChangesHandled();
                    added = true;
                }
            }

            if (!added)
            {
                mRenderList.Remove(q);
            }

            mRenderListDirty = true;
        }
Exemplo n.º 2
0
        private void _renderVertexBuffer()
        {
            if (mRenderList.Count == 0 || (mVertexBufferUsage == 0))
            {
                return;
            }

            uint bufferPosition = 0;

            /*
             * Since mRenderList is sorted by zOrder and by Texture, we can send quads with similar textures into one renderOperation.
             * Everything rendered in one _render call will receive the texture set previously by _setTexture.
             */
            for (int it = 0; it < mRenderList.Count; it++)
            {
                QuickGUIQuad iq             = mRenderList[it];
                string       currentTexture = iq.getTextureName();
                mRenderOperation.vertexData.vertexStart = bufferPosition;
                // Iterate over quads with the same texture.
                while ((it < mRenderList.Count) && (iq.getTextureName() == currentTexture))
                {
                    bufferPosition += QuickGUIQuad.VERTEX_PER_QUAD;
                    ++it;
                }
                // render quads
                mRenderOperation.vertexData.vertexCount = bufferPosition - mRenderOperation.vertexData.vertexStart;
                mRenderSystem._setTexture(0, true, currentTexture);
                initRenderState();
                mRenderSystem._render(mRenderOperation);

                // with the while loop it is possible to iterate to the end of the list.
                // At this point the for loop will increment it again, causing a crash.
                if (it == mRenderList.Count)
                {
                    break;
                }
            }
        }