/*
 * Reverse Antialiasing Shader
 * http://kdepepo.wordpress.com/2012/08/15/reverse-antialiasing-for-image-scaling/
 *
 * Adapted from the C source (see Copyright below) to shader
 * cg language by Hyllian/Jararaca - sergiogdb@gmail.com
 *
 * Adapted from the cg to glsl edgbla - edgbla@yandex.ru
 *
 * This shader works best using 2x scale. 
 */

/* source: http://imagezero.maxiom.de/files/ppmdouble.c
 *
 * Copyright (c) 2012, Christoph Feck <christoph@maxiom.de>
 * All Rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

uniform vec4 OGL2Param;
uniform vec4 OGL2Size;
uniform vec4 OGL2InvSize;

void main()
{
	gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_FrontColor = gl_Color;

    //    A1 B1 C1
    // A0  A  B  C C4
    // D0  D  E  F F4
    // G0  G  H  I I4
    //    G5 H5 I5

    vec2 ps = vec2(OGL2InvSize.x, OGL2InvSize.y);

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_TexCoord[1] = gl_MultiTexCoord0.xxxy + vec4(      -ps.x,     0, ps.x, -2.0 * ps.y); // A1 B1 C1
    gl_TexCoord[2] = gl_MultiTexCoord0.xxxy + vec4(      -ps.x,     0, ps.x,       -ps.y); //  A  B  C
    gl_TexCoord[3] = gl_MultiTexCoord0.xxxy + vec4(      -ps.x,     0, ps.x,           0); //  D  E  F
    gl_TexCoord[4] = gl_MultiTexCoord0.xxxy + vec4(      -ps.x,     0, ps.x,        ps.y); //  G  H  I
    gl_TexCoord[5] = gl_MultiTexCoord0.xxxy + vec4(      -ps.x,     0, ps.x,  2.0 * ps.y); // G5 H5 I5
    gl_TexCoord[6] = gl_MultiTexCoord0.xyyy + vec4(-2.0 * ps.x, -ps.y,    0,        ps.y); // A0 D0 G0
    gl_TexCoord[7] = gl_MultiTexCoord0.xyyy + vec4( 2.0 * ps.x, -ps.y,    0,        ps.y); // C4 F4 I4
}
