PDA

View Full Version : Viewports vs. Scissoring



godofskies8
11-19-2004, 08:44 PM
Hi,

Could someone please let me know the tradeoffs involved in creating multiple sub-windows in a single window using multiple viewports vs using multiple scissoring. I am not sure which would be faster.

Also, once I create a sub-window, how do I specify a symmetric perspective matrix relative to that sub-window.

Any help is greatly appreciated.
Thanks

sqrt[-1]
11-19-2004, 09:23 PM
I think you will find that you have to do both viewport and scissoring (glViewport/glScissor if that is what I think you mean)

The reason being is that when you call glViewport, it is not a scissor, so rendering can occur outside these bounds.

See issue 10 off the main OpenGL page:
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

godofskies8
11-19-2004, 10:48 PM
Hi,

I am sorry for not being more elaborate with my question. I encountered the problem that you mention, but I could solve it by clearing the depth buffer every time I wanted to draw on a new viewport. I was able to achieve similar satisfactiry results by defining four scissor screens within the main window. However, I must decide on one approach and proceed. Given that I have both methods running, which one will be less time intensive. This will matter a lot when screen complexity increases?

Thanks

IronicResearch
11-20-2004, 09:29 AM
With all due respect to the cited pitfall reference, in most cases the viewport is entirely adequate for clipping the rasterized pixels since the viewport dimensions form the last stage in the 3D-to-2D transform. The unusual case in the pitfall example actually refers to certain boundary condition vertexes *disappearing* since clipping is actually determined by the perspective projection planes.

However if your model is entirely visible within the viewport this is not going to happen. In no case will pixels ever "bleed" outside of the viewport region so you wouldn't have to consider scissoring.

Also what you might consider creating borderless child windows to compose each of the visible views within your main window. In this configuration you could eventually create separate GL rendering contexts for each subwindow and leverage muti-threaded rendering, which is what 3DStudio does for multiple views.

jwatte
11-20-2004, 09:35 AM
The viewport transform is just another transform in the pipeline. It's really no different from the others. It has to be done, no matter what the viewport is set as. Thus, if you set a viewport, clear, and draw, it'll be as fast as if you set a scissor, change perspective, and draw.

I would use the viewport mechanism, because it's more natural. I wouldn't create multiple contexts, because that would require mirroring state between the contexts, which is a major annoyance.

l_belev
11-20-2004, 10:13 AM
Both viewport transform and scissor are always done by the hw, so in that sense they're costless. (yes, the scissor too - even in fullscreen the hv must cut off the out of screen parts) There's no penalty for them being in whatever state whatsoever. So whenever they can be of any help for you - dont hezitate to use them (one of them or the both - does not matter).

martin_marinov
11-23-2004, 07:06 AM
Hello,

I use only viewports for displaying multiple scene views at once. About the perspective question I use gluPerspective this way:


void Viewport::SetViewportRect(const CWinRect& rectViewport)
{
m_rectViewport = rectViewport;

m_rectModel.right = m_rectViewport.Width()/2;
m_rectModel.left = - m_rectModel.right;

m_rectModel.top = m_rectViewport.Height()/2;
m_rectModel.bottom = - m_rectModel.top;

//model transform is left unchanged
rc_->MultPerspectiveMatrix(m_rectModel);
}

void COglRenderer::MultPerspectiveMatrix(const CWinRect& rect)
{
math_real dAspect = fabs(rect.Height() ? (math_real)rect.Width()/(math_real)rect.Height(): 1.0);
OGL_CHECK(::gluPerspective(OGL_PERSPECTIVE_ANGLE, dAspect, OGL_CLIP_NEAR, OGL_CLIP_FAR));
}(rc_ points to an instance of COglRenderer)

Regards
Martin

cass
11-23-2004, 01:33 PM
As jwatte states, viewport is just a transform, however, what makes it seem kindof like scissor is that it is post-clip.

In general you probably want to use both viewport and scissor. They are separate functions with different effects, though, so as long as you know what you're doing, you can abuse them however you like. :)

Thanks -
Cass