Jump to content

  • Log In with Google      Sign In   
  • Create Account

D3DXSprite + Scissor Rect


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Juliean   GDNet+   -  Reputation: 2723

Like
0Likes
Like

Posted 02 March 2013 - 08:52 AM

Hello,

 

I'm experiencing a problem when trying to use the DX9 ScissorRect to clip my gui objects content (e.g. a graphic that is going beyond the borders of my window). Now, I'm using the ID3DXSprite-interface to render the objects. My problem is this: Whenever I set the scissor rect using Device->SetScissorRect(), only the last set scissor rect gets applied, and everything gets clipped to this area. Device-state is set, I checked with PIX and NPerfHUD, its simply that when calling sprite.end(), the last set scissor rect will be used to clip all of the batched draw-calls. Here is my gui render loop:

 

 

    //loop all registered objects
    for(vector<GuiObject*>::iterator jj = m_vObjects.begin();jj!=m_vObjects.end();++jj)
    {
        //aquire render data
        const vector<RenderData>& vData =  (*jj)->GetRenderData();
        //draw each objects subpart
        for(vector<RenderData>::const_iterator ii = vData.begin(); ii!=vData.end();++ii)
        {
            //check for label
            if(ii->sLabel.size() == 0)
            {
                //check for texture
                if(ii->pTexture == NULL)
                {
                    //check for filename
                    if(ii->sFileName.size() == 0)
                        //draw from layout
                        m_pSprite->SetTexture(m_pTexture);
                    else
                        //draw from file
                        m_pSprite->SetTexture(m_pGraphicsModule->NewTextureFile(ii->sFileName));
                }
                else
                    //draw from texture
                    m_pSprite->SetTexture(ii->pTexture);

                //setup sprite
                m_pSprite->SetZ(ii->z);
                m_pSprite->SetSourceRect(ii->rSourceRect);
                m_pSprite->SetX(ii->rDestRect.x);
                m_pSprite->SetY(ii->rDestRect.y);    
                m_pSprite->SetWidth(ii->rDestRect.width);
                m_pSprite->SetHeight(ii->rDestRect.height);
                //draw
                m_pSprite->Draw();
            }
            else
            {
                //draw label
                m_pFontWriter->DrawTextW(ii->rDestRect,ii->sLabel.c_str(), ii->labelFlags, ii->z);
            }
        }
        //set viewport to clip objects content
        //todo: use only one viewport and Set() it
        m_pSprite->SetViewport(m_pGraphicsModule->NewViewport((*jj)->GetViewport()));
        m_pSprite->ApplyViewport();
    }
    //reset viewport, uncommenting will show everything
    //m_pSprite->SetViewport(m_pGraphicsModule->Screenport());
    //m_pSprite->ApplyViewport();

m_pSprite->Draw() will issue a ID3DXSprite draw call, m_pSprite->ApplyViewport() will call SetScissorRect to the device. Now, if I uncomment the last two lines, everything will be shown - but no clipping anywhere.

 

I figured out a way to get it to work: If I call sprite->end() and sprite->begin() when applying the viewport, everything will work fine, since all prior draw-calls gets issued to the device. This is not an option since it would be too slow; or lets say so: I want to use the speed the sprite-interface offers me by batching all of my draw calls.

 

Is there any way to use a ScissorRect for a certain sprite->draw() call without having to end() and begin() the sprite before?

 

EDIT: Problem solved. There really is no way to regularly change the scissor rect between sprite->draw() calls, but calling sprite->flush() before changing the rect works, and almost as fast as before (163 FPS original, 148 FPS begin()->end(), and 159 FPS; I know FPS is a bad measure but just to give you an idea).


Edited by The King2, 02 March 2013 - 11:09 AM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS