/*
 * This source file is part of KEOS (Free 3D Engine)
 * For the latest info, see http://www.keosengine.org/
 * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
 * 
 * This program 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 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
 * http://www.gnu.org/copyleft/lesser.txt.
 *
 */

#include "KeosOGLEnum.h"

namespace Keos
{
    //=======================================================================
    // COGLEnum implementation
    //=======================================================================

    //-----------------------------------------------------------------------
    GLenum COGLEnum::MatrixType[] =
    {
        GL_MODELVIEW,
        GL_PROJECTION,
        GL_TEXTURE,
        GL_TEXTURE,
        GL_TEXTURE,
        GL_TEXTURE
    };

    //-----------------------------------------------------------------------
    GLenum COGLEnum::MatrixType2[] =
    {
        GL_MODELVIEW_MATRIX,
        GL_PROJECTION_MATRIX,
        GL_TEXTURE_MATRIX,
        GL_TEXTURE_MATRIX,
        GL_TEXTURE_MATRIX,
        GL_TEXTURE_MATRIX
    };

    //-----------------------------------------------------------------------
    COGLEnum::TPixelFmt COGLEnum::PixelFormat[] =
    {
        {GL_LUMINANCE,       GL_LUMINANCE8,                    GL_UNSIGNED_BYTE},
        {GL_LUMINANCE_ALPHA, GL_LUMINANCE8_ALPHA8,             GL_UNSIGNED_BYTE},
        {GL_BGRA,            GL_RGB5_A1,                       GL_UNSIGNED_SHORT_1_5_5_5_REV},
        {GL_BGRA,            GL_RGBA4,                         GL_UNSIGNED_SHORT_4_4_4_4_REV},
        {GL_BGR,             GL_RGB8,                          GL_UNSIGNED_BYTE},
        {GL_BGRA,            GL_RGBA8,                         GL_UNSIGNED_BYTE},
        {GL_BGR,             GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 0},
        {GL_BGRA,            GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 0},
        {GL_BGRA,            GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 0}
    };

    //-----------------------------------------------------------------------
    GLenum COGLEnum::Blend[] =
    {
        GL_SRC_ALPHA,
        GL_ONE_MINUS_SRC_ALPHA,
        GL_DST_ALPHA,
        GL_ONE_MINUS_DST_ALPHA,
        GL_SRC_COLOR,
        GL_ONE_MINUS_SRC_COLOR,
        GL_DST_COLOR,
        GL_ONE_MINUS_DST_COLOR,
        GL_ONE,
        GL_ZERO
    };
    
    //-----------------------------------------------------------------------
    GLenum COGLEnum::TextureOp[] =
    {
        GL_REPLACE,
        GL_ADD,
        GL_MODULATE,
        GL_REPLACE,
        GL_ADD,
        GL_MODULATE
    };

    //-----------------------------------------------------------------------
    GLenum COGLEnum::TextureArg[] =
    {
        GL_PRIMARY_COLOR_EXT,
        GL_TEXTURE,
        GL_PREVIOUS_EXT,
        GL_CONSTANT_EXT
    };

    //-----------------------------------------------------------------------
    GLenum COGLEnum::RenderParameter[] =
    {
        0,
        GL_BLEND,
    };

    //-----------------------------------------------------------------------
    ulong COGLEnum::BufferFlags(ulong nFlags)
    {
        // @todo pkoi GL_STATIC_DRAW_ARB pour les buffers dynamique ?
        return (nFlags & BUF_DYNAMIC ? GL_STATIC_DRAW_ARB : GL_STATIC_DRAW_ARB);
    }

    //-----------------------------------------------------------------------
    ulong COGLEnum::LockFlags(ulong nFlags)
    {
        ulong nLockFlags = GL_READ_WRITE_ARB;
        if (nFlags & LOCK_READONLY)  nLockFlags = GL_READ_ONLY_ARB;
        if (nFlags & LOCK_WRITEONLY) nLockFlags = GL_WRITE_ONLY_ARB;

        return nLockFlags;
    }

    //-----------------------------------------------------------------------
    GLenum COGLEnum::Get(TMatrixType Value)
    {
        return MatrixType[Value];
    }

    //-----------------------------------------------------------------------
    GLenum COGLEnum::GetMatrix(TMatrixType Value)
    {
        return MatrixType2[Value];
    }

    //-----------------------------------------------------------------------    
    COGLEnum::TPixelFmt COGLEnum::Get(TPixelFormat Value)
    {
        return PixelFormat[Value];
    }

    //-----------------------------------------------------------------------
    GLenum COGLEnum::Get(TBlend Value)
    {
        return Blend[Value];
    }

    //-----------------------------------------------------------------------
    GLenum COGLEnum::Get(TTextureOp Value)
    {
        return TextureOp[Value];
    }

    //-----------------------------------------------------------------------
    GLenum COGLEnum::Get(TTextureArg Value)
    {
        return TextureArg[Value];
    }

    //-----------------------------------------------------------------------
    GLenum COGLEnum::Get(TRenderParameter Value)
    {
        return RenderParameter[Value];
    }

} // namespace Keos
