// Wild Magic Source Code
// David Eberly
// http://www.geometrictools.com
// Copyright (c) 1998-2008
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or (at
// your option) any later version.  The license is available for reading at
// either of the locations:
//     http://www.gnu.org/copyleft/lgpl.html
//     http://www.geometrictools.com/License/WildMagicLicense.pdf
//
// Version: 4.0.0 (2006/06/28)

#include "Wm4OpenGLRendererPCH.h"
#include "Wm4OpenGLRenderer.h"
#include "Wm4Camera.h"
using namespace Wm4;

//----------------------------------------------------------------------------
void OpenGLRenderer::OnViewportChange ()
{
    float fPortL, fPortR, fPortT, fPortB;
    if (m_pkCamera)
    {
        // 3D applications use cameras.
        m_pkCamera->GetViewport(fPortL,fPortR,fPortT,fPortB);
    }
    else
    {
        // 2D applications do not use cameras.
        fPortL = 0.0f;
        fPortR = 1.0f;
        fPortT = 1.0f;
        fPortB = 0.0f;
    }

    // OpenGL defines the full-sized viewport to have origin at the lower
    // left corner of the screen.  The fB value specifies the relative
    // distance from the bottom of the screen.  Wild Magic also uses this
    // convention, but DirectX does not (in which case iY is computed
    // differently for DirectX).
    GLint iX = (GLint)(fPortL*m_iWidth);
    GLint iY = (GLint)(fPortB*m_iHeight);  // See note above.
    GLsizei iW = (GLsizei)((fPortR - fPortL)*m_iWidth);
    GLsizei iH = (GLsizei)((fPortT - fPortB)*m_iHeight);
    glViewport(iX,iY,iW,iH);
}
//----------------------------------------------------------------------------
void OpenGLRenderer::OnDepthRangeChange ()
{
    if (m_pkCamera)
    {
        float fPortN, fPortF;
        m_pkCamera->GetDepthRange(fPortN,fPortF);
        glDepthRange((GLclampd)fPortN,(GLclampd)fPortF);
    }
    else
    {
        glDepthRange(0.0,1.0);
    }
}
//----------------------------------------------------------------------------
