src/java.desktop/share/native/common/java2d/opengl/OGLRenderer.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
     2
 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <jlong.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <jni_util.h>
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    30
#include <math.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "sun_java2d_opengl_OGLRenderer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "OGLRenderer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "OGLRenderQueue.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "OGLSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Note: Some of the methods in this file apply a "magic number"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * translation to line segments.  The OpenGL specification lays out the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * "diamond exit rule" for line rasterization, but it is loose enough to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * allow for a wide range of line rendering hardware.  (It appears that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * some hardware, such as the Nvidia GeForce2 series, does not even meet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * the spec in all cases.)  As such it is difficult to find a mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * between the Java2D and OpenGL line specs that works consistently across
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * all hardware combinations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Therefore the "magic numbers" you see here have been empirically derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * after testing on a variety of graphics hardware in order to find some
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * reasonable middle ground between the two specifications.  The general
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * approach is to apply a fractional translation to vertices so that they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * hit pixel centers and therefore touch the same pixels as in our other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * pipelines.  Emphasis was placed on finding values so that OGL lines with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * a slope of +/- 1 hit all the same pixels as our other (software) loops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * The stepping in other diagonal lines rendered with OGL may deviate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * slightly from those rendered with our software loops, but the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * important thing is that these magic numbers ensure that all OGL lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * hit the same endpoints as our software loops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * If you find it necessary to change any of these magic numbers in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * future, just be sure that you test the changes across a variety of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * hardware to ensure consistent rendering everywhere.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
OGLRenderer_DrawLine(OGLContext *oglc, jint x1, jint y1, jint x2, jint y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_DrawLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    CHECK_PREVIOUS_OP(GL_LINES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    if (y1 == y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        // horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        GLfloat fx1 = (GLfloat)x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        GLfloat fx2 = (GLfloat)x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        GLfloat fy  = ((GLfloat)y1) + 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (x1 > x2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            GLfloat t = fx1; fx1 = fx2; fx2 = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        j2d_glVertex2f(fx1+0.2f, fy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        j2d_glVertex2f(fx2+1.2f, fy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    } else if (x1 == x2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        GLfloat fx  = ((GLfloat)x1) + 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        GLfloat fy1 = (GLfloat)y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        GLfloat fy2 = (GLfloat)y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (y1 > y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            GLfloat t = fy1; fy1 = fy2; fy2 = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        j2d_glVertex2f(fx, fy1+0.2f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        j2d_glVertex2f(fx, fy2+1.2f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // diagonal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        GLfloat fx1 = (GLfloat)x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        GLfloat fy1 = (GLfloat)y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        GLfloat fx2 = (GLfloat)x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        GLfloat fy2 = (GLfloat)y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (x1 < x2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            fx1 += 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            fx2 += 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            fx1 += 0.8f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            fx2 -= 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (y1 < y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            fy1 += 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            fy2 += 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            fy1 += 0.8f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            fy2 -= 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        j2d_glVertex2f(fx1, fy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        j2d_glVertex2f(fx2, fy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
OGLRenderer_DrawRect(OGLContext *oglc, jint x, jint y, jint w, jint h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_DrawRect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    if (w < 0 || h < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    if (w < 2 || h < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // If one dimension is less than 2 then there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        // gap in the middle - draw a solid filled rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        CHECK_PREVIOUS_OP(GL_QUADS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        GLRECT_BODY_XYWH(x, y, w+1, h+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        GLfloat fx1 = ((GLfloat)x) + 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        GLfloat fy1 = ((GLfloat)y) + 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        GLfloat fx2 = fx1 + ((GLfloat)w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        GLfloat fy2 = fy1 + ((GLfloat)h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // Avoid drawing the endpoints twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // Also prefer including the endpoints in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // horizontal sections which draw pixels faster.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        CHECK_PREVIOUS_OP(GL_LINES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        // top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        j2d_glVertex2f(fx1,      fy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        j2d_glVertex2f(fx2+1.0f, fy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        j2d_glVertex2f(fx2,      fy1+1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        j2d_glVertex2f(fx2,      fy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        j2d_glVertex2f(fx1,      fy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        j2d_glVertex2f(fx2+1.0f, fy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        j2d_glVertex2f(fx1,      fy1+1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        j2d_glVertex2f(fx1,      fy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
OGLRenderer_DrawPoly(OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                     jint nPoints, jint isClosed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                     jint transX, jint transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                     jint *xPoints, jint *yPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    jboolean isEmpty = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    jint mx, my;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_DrawPoly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    if (xPoints == NULL || yPoints == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                      "OGLRenderer_DrawPoly: points array is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    // Note that BufferedRenderPipe.drawPoly() has already rejected polys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    // with nPoints<2, so we can be certain here that we have nPoints>=2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    mx = xPoints[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    my = yPoints[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    CHECK_PREVIOUS_OP(GL_LINE_STRIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    for (i = 0; i < nPoints; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        jint x = xPoints[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        jint y = yPoints[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        isEmpty = isEmpty && (x == mx && y == my);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // Translate each vertex by a fraction so that we hit pixel centers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        j2d_glVertex2f((GLfloat)(x + transX) + 0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                       (GLfloat)(y + transY) + 0.5f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    if (isClosed && !isEmpty &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        (xPoints[nPoints-1] != mx ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         yPoints[nPoints-1] != my))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // In this case, the polyline's start and end positions are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // different and need to be closed manually; we do this by adding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // one more segment back to the starting position.  Note that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // do not need to fill in the last pixel (as we do in the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // block) because we are returning to the starting pixel, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // has already been filled in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        j2d_glVertex2f((GLfloat)(mx + transX) + 0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                       (GLfloat)(my + transY) + 0.5f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        RESET_PREVIOUS_OP(); // so that we don't leave the line strip open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    } else if (!isClosed || isEmpty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        // OpenGL omits the last pixel in a polyline, so we fix this by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        // adding a one-pixel segment at the end.  Also, if the polyline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        // never went anywhere (isEmpty is true), we need to use this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // workaround to ensure that a single pixel is touched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        CHECK_PREVIOUS_OP(GL_LINES); // this closes the line strip first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        mx = xPoints[nPoints-1] + transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        my = yPoints[nPoints-1] + transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        j2d_glVertex2i(mx, my);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        j2d_glVertex2i(mx+1, my+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // no need for RESET_PREVIOUS_OP, as the line strip is no longer open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        RESET_PREVIOUS_OP(); // so that we don't leave the line strip open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
Java_sun_java2d_opengl_OGLRenderer_drawPoly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    (JNIEnv *env, jobject oglr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     jintArray xpointsArray, jintArray ypointsArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     jint nPoints, jboolean isClosed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     jint transX, jint transY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    jint *xPoints, *yPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_drawPoly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    xPoints = (jint *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        (*env)->GetPrimitiveArrayCritical(env, xpointsArray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    if (xPoints != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        yPoints = (jint *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            (*env)->GetPrimitiveArrayCritical(env, ypointsArray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (yPoints != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            OGLContext *oglc = OGLRenderQueue_GetCurrentContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            OGLRenderer_DrawPoly(oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                 nPoints, isClosed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                 transX, transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                 xPoints, yPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            // 6358147: reset current state, and ensure rendering is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            // flushed to dest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if (oglc != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                RESET_PREVIOUS_OP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                j2d_glFlush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            (*env)->ReleasePrimitiveArrayCritical(env, ypointsArray, yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                                  JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        (*env)->ReleasePrimitiveArrayCritical(env, xpointsArray, xPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                              JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
OGLRenderer_DrawScanlines(OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                          jint scanlineCount, jint *scanlines)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_DrawScanlines");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    RETURN_IF_NULL(scanlines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    CHECK_PREVIOUS_OP(GL_LINES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    while (scanlineCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // Translate each vertex by a fraction so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        // that we hit pixel centers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        GLfloat x1 = ((GLfloat)*(scanlines++)) + 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        GLfloat x2 = ((GLfloat)*(scanlines++)) + 1.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        GLfloat y  = ((GLfloat)*(scanlines++)) + 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        j2d_glVertex2f(x1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        j2d_glVertex2f(x2, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        scanlineCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
OGLRenderer_FillRect(OGLContext *oglc, jint x, jint y, jint w, jint h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_FillRect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    CHECK_PREVIOUS_OP(GL_QUADS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    GLRECT_BODY_XYWH(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
OGLRenderer_FillSpans(OGLContext *oglc, jint spanCount, jint *spans)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_FillSpans");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    RETURN_IF_NULL(spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    CHECK_PREVIOUS_OP(GL_QUADS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    while (spanCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        jint x1 = *(spans++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        jint y1 = *(spans++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        jint x2 = *(spans++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        jint y2 = *(spans++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        GLRECT_BODY_XYXY(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        spanCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   330
#define FILL_PGRAM(fx11, fy11, dx21, dy21, dx12, dy12) \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   331
    do { \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   332
        j2d_glVertex2f(fx11,               fy11); \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   333
        j2d_glVertex2f(fx11 + dx21,        fy11 + dy21); \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   334
        j2d_glVertex2f(fx11 + dx21 + dx12, fy11 + dy21 + dy12); \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   335
        j2d_glVertex2f(fx11 + dx12,        fy11 + dy12); \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   336
    } while (0)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   337
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   338
void
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   339
OGLRenderer_FillParallelogram(OGLContext *oglc,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   340
                              jfloat fx11, jfloat fy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   341
                              jfloat dx21, jfloat dy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   342
                              jfloat dx12, jfloat dy12)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   343
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   344
    J2dTraceLn6(J2D_TRACE_INFO,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   345
                "OGLRenderer_FillParallelogram "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   346
                "(x=%6.2f y=%6.2f "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   347
                "dx1=%6.2f dy1=%6.2f "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   348
                "dx2=%6.2f dy2=%6.2f)",
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   349
                fx11, fy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   350
                dx21, dy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   351
                dx12, dy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   352
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   353
    RETURN_IF_NULL(oglc);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   354
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   355
    CHECK_PREVIOUS_OP(GL_QUADS);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   356
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   357
    FILL_PGRAM(fx11, fy11, dx21, dy21, dx12, dy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   358
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   359
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   360
void
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   361
OGLRenderer_DrawParallelogram(OGLContext *oglc,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   362
                              jfloat fx11, jfloat fy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   363
                              jfloat dx21, jfloat dy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   364
                              jfloat dx12, jfloat dy12,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   365
                              jfloat lwr21, jfloat lwr12)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   366
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   367
    // dx,dy for line width in the "21" and "12" directions.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   368
    jfloat ldx21 = dx21 * lwr21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   369
    jfloat ldy21 = dy21 * lwr21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   370
    jfloat ldx12 = dx12 * lwr12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   371
    jfloat ldy12 = dy12 * lwr12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   372
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   373
    // calculate origin of the outer parallelogram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   374
    jfloat ox11 = fx11 - (ldx21 + ldx12) / 2.0f;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   375
    jfloat oy11 = fy11 - (ldy21 + ldy12) / 2.0f;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   376
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   377
    J2dTraceLn8(J2D_TRACE_INFO,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   378
                "OGLRenderer_DrawParallelogram "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   379
                "(x=%6.2f y=%6.2f "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   380
                "dx1=%6.2f dy1=%6.2f lwr1=%6.2f "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   381
                "dx2=%6.2f dy2=%6.2f lwr2=%6.2f)",
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   382
                fx11, fy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   383
                dx21, dy21, lwr21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   384
                dx12, dy12, lwr12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   385
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   386
    RETURN_IF_NULL(oglc);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   387
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   388
    CHECK_PREVIOUS_OP(GL_QUADS);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   389
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   390
    // Only need to generate 4 quads if the interior still
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   391
    // has a hole in it (i.e. if the line width ratio was
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   392
    // less than 1.0)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   393
    if (lwr21 < 1.0f && lwr12 < 1.0f) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   394
        // Note: "TOP", "BOTTOM", "LEFT" and "RIGHT" here are
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   395
        // relative to whether the dxNN variables are positive
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   396
        // and negative.  The math works fine regardless of
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   397
        // their signs, but for conceptual simplicity the
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   398
        // comments will refer to the sides as if the dxNN
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   399
        // were all positive.  "TOP" and "BOTTOM" segments
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   400
        // are defined by the dxy21 deltas.  "LEFT" and "RIGHT"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   401
        // segments are defined by the dxy12 deltas.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   402
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   403
        // Each segment includes its starting corner and comes
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   404
        // to just short of the following corner.  Thus, each
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   405
        // corner is included just once and the only lengths
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   406
        // needed are the original parallelogram delta lengths
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   407
        // and the "line width deltas".  The sides will cover
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   408
        // the following relative territories:
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   409
        //
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   410
        //     T T T T T R
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   411
        //      L         R
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   412
        //       L         R
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   413
        //        L         R
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   414
        //         L         R
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   415
        //          L B B B B B
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   416
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   417
        // TOP segment, to left side of RIGHT edge
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   418
        // "width" of original pgram, "height" of hor. line size
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   419
        fx11 = ox11;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   420
        fy11 = oy11;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   421
        FILL_PGRAM(fx11, fy11, dx21, dy21, ldx12, ldy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   422
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   423
        // RIGHT segment, to top of BOTTOM edge
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   424
        // "width" of vert. line size , "height" of original pgram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   425
        fx11 = ox11 + dx21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   426
        fy11 = oy11 + dy21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   427
        FILL_PGRAM(fx11, fy11, ldx21, ldy21, dx12, dy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   428
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   429
        // BOTTOM segment, from right side of LEFT edge
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   430
        // "width" of original pgram, "height" of hor. line size
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   431
        fx11 = ox11 + dx12 + ldx21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   432
        fy11 = oy11 + dy12 + ldy21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   433
        FILL_PGRAM(fx11, fy11, dx21, dy21, ldx12, ldy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   434
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   435
        // LEFT segment, from bottom of TOP edge
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   436
        // "width" of vert. line size , "height" of inner pgram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   437
        fx11 = ox11 + ldx12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   438
        fy11 = oy11 + ldy12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   439
        FILL_PGRAM(fx11, fy11, ldx21, ldy21, dx12, dy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   440
    } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   441
        // The line width ratios were large enough to consume
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   442
        // the entire hole in the middle of the parallelogram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   443
        // so we can just issue one large quad for the outer
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   444
        // parallelogram.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   445
        dx21 += ldx21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   446
        dy21 += ldy21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   447
        dx12 += ldx12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   448
        dy12 += ldy12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   449
        FILL_PGRAM(ox11, oy11, dx21, dy21, dx12, dy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   450
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   451
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   452
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   453
static GLhandleARB aaPgramProgram = 0;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   454
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   455
/*
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   456
 * This shader fills the space between an outer and inner parallelogram.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   457
 * It can be used to draw an outline by specifying both inner and outer
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   458
 * values.  It fills pixels by estimating what portion falls inside the
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   459
 * outer shape, and subtracting an estimate of what portion falls inside
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   460
 * the inner shape.  Specifying both inner and outer values produces a
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   461
 * standard "wide outline".  Specifying an inner shape that falls far
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   462
 * outside the outer shape allows the same shader to fill the outer
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   463
 * shape entirely since pixels that fall within the outer shape are never
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   464
 * inside the inner shape and so they are filled based solely on their
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   465
 * coverage of the outer shape.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   466
 *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   467
 * The setup code renders this shader over the bounds of the outer
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   468
 * shape (or the only shape in the case of a fill operation) and
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   469
 * sets the texture 0 coordinates so that 0,0=>0,1=>1,1=>1,0 in those
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   470
 * texture coordinates map to the four corners of the parallelogram.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   471
 * Similarly the texture 1 coordinates map the inner shape to the
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   472
 * unit square as well, but in a different coordinate system.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   473
 *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   474
 * When viewed in the texture coordinate systems the parallelograms
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   475
 * we are filling are unit squares, but the pixels have then become
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   476
 * tiny parallelograms themselves.  Both of the texture coordinate
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   477
 * systems are affine transforms so the rate of change in X and Y
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   478
 * of the texture coordinates are essentially constants and happen
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   479
 * to correspond to the size and direction of the slanted sides of
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   480
 * the distorted pixels relative to the "square mapped" boundary
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   481
 * of the parallelograms.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   482
 *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   483
 * The shader uses the dFdx() and dFdy() functions to measure the "rate
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   484
 * of change" of these texture coordinates and thus gets an accurate
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   485
 * measure of the size and shape of a pixel relative to the two
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   486
 * parallelograms.  It then uses the bounds of the size and shape
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   487
 * of a pixel to intersect with the unit square to estimate the
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   488
 * coverage of the pixel.  Unfortunately, without a lot more work
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   489
 * to calculate the exact area of intersection between a unit
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   490
 * square (the original parallelogram) and a parallelogram (the
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   491
 * distorted pixel), this shader only approximates the pixel
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   492
 * coverage, but emperically the estimate is very useful and
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   493
 * produces visually pleasing results, if not theoretically accurate.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   494
 */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   495
static const char *aaPgramShaderSource =
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   496
    "void main() {"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   497
    // Calculate the vectors for the "legs" of the pixel parallelogram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   498
    // for the outer parallelogram.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   499
    "    vec2 oleg1 = dFdx(gl_TexCoord[0].st);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   500
    "    vec2 oleg2 = dFdy(gl_TexCoord[0].st);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   501
    // Calculate the bounds of the distorted pixel parallelogram.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   502
    "    vec2 corner = gl_TexCoord[0].st - (oleg1+oleg2)/2.0;"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   503
    "    vec2 omin = min(corner, corner+oleg1);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   504
    "    omin = min(omin, corner+oleg2);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   505
    "    omin = min(omin, corner+oleg1+oleg2);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   506
    "    vec2 omax = max(corner, corner+oleg1);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   507
    "    omax = max(omax, corner+oleg2);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   508
    "    omax = max(omax, corner+oleg1+oleg2);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   509
    // Calculate the vectors for the "legs" of the pixel parallelogram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   510
    // for the inner parallelogram.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   511
    "    vec2 ileg1 = dFdx(gl_TexCoord[1].st);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   512
    "    vec2 ileg2 = dFdy(gl_TexCoord[1].st);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   513
    // Calculate the bounds of the distorted pixel parallelogram.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   514
    "    corner = gl_TexCoord[1].st - (ileg1+ileg2)/2.0;"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   515
    "    vec2 imin = min(corner, corner+ileg1);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   516
    "    imin = min(imin, corner+ileg2);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   517
    "    imin = min(imin, corner+ileg1+ileg2);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   518
    "    vec2 imax = max(corner, corner+ileg1);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   519
    "    imax = max(imax, corner+ileg2);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   520
    "    imax = max(imax, corner+ileg1+ileg2);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   521
    // Clamp the bounds of the parallelograms to the unit square to
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   522
    // estimate the intersection of the pixel parallelogram with
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   523
    // the unit square.  The ratio of the 2 rectangle areas is a
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   524
    // reasonable estimate of the proportion of coverage.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   525
    "    vec2 o1 = clamp(omin, 0.0, 1.0);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   526
    "    vec2 o2 = clamp(omax, 0.0, 1.0);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   527
    "    float oint = (o2.y-o1.y)*(o2.x-o1.x);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   528
    "    float oarea = (omax.y-omin.y)*(omax.x-omin.x);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   529
    "    vec2 i1 = clamp(imin, 0.0, 1.0);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   530
    "    vec2 i2 = clamp(imax, 0.0, 1.0);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   531
    "    float iint = (i2.y-i1.y)*(i2.x-i1.x);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   532
    "    float iarea = (imax.y-imin.y)*(imax.x-imin.x);"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   533
    // Proportion of pixel in outer shape minus the proportion
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   534
    // of pixel in the inner shape == the coverage of the pixel
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   535
    // in the area between the two.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   536
    "    float coverage = oint/oarea - iint / iarea;"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   537
    "    gl_FragColor = gl_Color * coverage;"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   538
    "}";
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   539
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   540
#define ADJUST_PGRAM(V1, DV, V2) \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   541
    do { \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   542
        if ((DV) >= 0) { \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   543
            (V2) += (DV); \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   544
        } else { \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   545
            (V1) += (DV); \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   546
        } \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   547
    } while (0)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   548
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   549
// Invert the following transform:
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   550
// DeltaT(0, 0) == (0,       0)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   551
// DeltaT(1, 0) == (DX1,     DY1)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   552
// DeltaT(0, 1) == (DX2,     DY2)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   553
// DeltaT(1, 1) == (DX1+DX2, DY1+DY2)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   554
// TM00 = DX1,   TM01 = DX2,   (TM02 = X11)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   555
// TM10 = DY1,   TM11 = DY2,   (TM12 = Y11)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   556
// Determinant = TM00*TM11 - TM01*TM10
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   557
//             =  DX1*DY2  -  DX2*DY1
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   558
// Inverse is:
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   559
// IM00 =  TM11/det,   IM01 = -TM01/det
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   560
// IM10 = -TM10/det,   IM11 =  TM00/det
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   561
// IM02 = (TM01 * TM12 - TM11 * TM02) / det,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   562
// IM12 = (TM10 * TM02 - TM00 * TM12) / det,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   563
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   564
#define DECLARE_MATRIX(MAT) \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   565
    jfloat MAT ## 00, MAT ## 01, MAT ## 02, MAT ## 10, MAT ## 11, MAT ## 12
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   566
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   567
#define GET_INVERTED_MATRIX(MAT, X11, Y11, DX1, DY1, DX2, DY2, RET_CODE) \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   568
    do { \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   569
        jfloat det = DX1*DY2 - DX2*DY1; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   570
        if (det == 0) { \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   571
            RET_CODE; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   572
        } \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   573
        MAT ## 00 = DY2/det; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   574
        MAT ## 01 = -DX2/det; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   575
        MAT ## 10 = -DY1/det; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   576
        MAT ## 11 = DX1/det; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   577
        MAT ## 02 = (DX2 * Y11 - DY2 * X11) / det; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   578
        MAT ## 12 = (DY1 * X11 - DX1 * Y11) / det; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   579
    } while (0)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   580
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   581
#define TRANSFORM(MAT, TX, TY, X, Y) \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   582
    do { \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   583
        TX = (X) * MAT ## 00 + (Y) * MAT ## 01 + MAT ## 02; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   584
        TY = (X) * MAT ## 10 + (Y) * MAT ## 11 + MAT ## 12; \
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   585
    } while (0)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   586
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   587
void
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   588
OGLRenderer_FillAAParallelogram(OGLContext *oglc, OGLSDOps *dstOps,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   589
                                jfloat fx11, jfloat fy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   590
                                jfloat dx21, jfloat dy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   591
                                jfloat dx12, jfloat dy12)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   592
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   593
    DECLARE_MATRIX(om);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   594
    // parameters for parallelogram bounding box
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   595
    jfloat bx11, by11, bx22, by22;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   596
    // parameters for uv texture coordinates of parallelogram corners
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   597
    jfloat u11, v11, u12, v12, u21, v21, u22, v22;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   598
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   599
    J2dTraceLn6(J2D_TRACE_INFO,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   600
                "OGLRenderer_FillAAParallelogram "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   601
                "(x=%6.2f y=%6.2f "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   602
                "dx1=%6.2f dy1=%6.2f "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   603
                "dx2=%6.2f dy2=%6.2f)",
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   604
                fx11, fy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   605
                dx21, dy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   606
                dx12, dy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   607
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   608
    RETURN_IF_NULL(oglc);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   609
    RETURN_IF_NULL(dstOps);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   610
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   611
    GET_INVERTED_MATRIX(om, fx11, fy11, dx21, dy21, dx12, dy12,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   612
                        return);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   613
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   614
    CHECK_PREVIOUS_OP(OGL_STATE_PGRAM_OP);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   615
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   616
    bx11 = bx22 = fx11;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   617
    by11 = by22 = fy11;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   618
    ADJUST_PGRAM(bx11, dx21, bx22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   619
    ADJUST_PGRAM(by11, dy21, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   620
    ADJUST_PGRAM(bx11, dx12, bx22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   621
    ADJUST_PGRAM(by11, dy12, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   622
    bx11 = (jfloat) floor(bx11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   623
    by11 = (jfloat) floor(by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   624
    bx22 = (jfloat) ceil(bx22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   625
    by22 = (jfloat) ceil(by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   626
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   627
    TRANSFORM(om, u11, v11, bx11, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   628
    TRANSFORM(om, u21, v21, bx22, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   629
    TRANSFORM(om, u12, v12, bx11, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   630
    TRANSFORM(om, u22, v22, bx22, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   631
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   632
    j2d_glBegin(GL_QUADS);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   633
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u11, v11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   634
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 5.f, 5.f);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   635
    j2d_glVertex2f(bx11, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   636
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u21, v21);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   637
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 6.f, 5.f);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   638
    j2d_glVertex2f(bx22, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   639
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u22, v22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   640
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 6.f, 6.f);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   641
    j2d_glVertex2f(bx22, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   642
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u12, v12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   643
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 5.f, 6.f);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   644
    j2d_glVertex2f(bx11, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   645
    j2d_glEnd();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   646
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   647
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   648
void
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   649
OGLRenderer_FillAAParallelogramInnerOuter(OGLContext *oglc, OGLSDOps *dstOps,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   650
                                          jfloat ox11, jfloat oy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   651
                                          jfloat ox21, jfloat oy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   652
                                          jfloat ox12, jfloat oy12,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   653
                                          jfloat ix11, jfloat iy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   654
                                          jfloat ix21, jfloat iy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   655
                                          jfloat ix12, jfloat iy12)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   656
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   657
    DECLARE_MATRIX(om);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   658
    DECLARE_MATRIX(im);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   659
    // parameters for parallelogram bounding box
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   660
    jfloat bx11, by11, bx22, by22;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   661
    // parameters for uv texture coordinates of outer parallelogram corners
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   662
    jfloat ou11, ov11, ou12, ov12, ou21, ov21, ou22, ov22;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   663
    // parameters for uv texture coordinates of inner parallelogram corners
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   664
    jfloat iu11, iv11, iu12, iv12, iu21, iv21, iu22, iv22;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   665
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   666
    RETURN_IF_NULL(oglc);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   667
    RETURN_IF_NULL(dstOps);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   668
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   669
    GET_INVERTED_MATRIX(im, ix11, iy11, ix21, iy21, ix12, iy12,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   670
                        // inner parallelogram is degenerate
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   671
                        // therefore it encloses no area
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   672
                        // fill outer
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   673
                        OGLRenderer_FillAAParallelogram(oglc, dstOps,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   674
                                                        ox11, oy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   675
                                                        ox21, oy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   676
                                                        ox12, oy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   677
                        return);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   678
    GET_INVERTED_MATRIX(om, ox11, oy11, ox21, oy21, ox12, oy12,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   679
                        return);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   680
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   681
    CHECK_PREVIOUS_OP(OGL_STATE_PGRAM_OP);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   682
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   683
    bx11 = bx22 = ox11;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   684
    by11 = by22 = oy11;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   685
    ADJUST_PGRAM(bx11, ox21, bx22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   686
    ADJUST_PGRAM(by11, oy21, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   687
    ADJUST_PGRAM(bx11, ox12, bx22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   688
    ADJUST_PGRAM(by11, oy12, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   689
    bx11 = (jfloat) floor(bx11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   690
    by11 = (jfloat) floor(by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   691
    bx22 = (jfloat) ceil(bx22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   692
    by22 = (jfloat) ceil(by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   693
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   694
    TRANSFORM(om, ou11, ov11, bx11, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   695
    TRANSFORM(om, ou21, ov21, bx22, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   696
    TRANSFORM(om, ou12, ov12, bx11, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   697
    TRANSFORM(om, ou22, ov22, bx22, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   698
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   699
    TRANSFORM(im, iu11, iv11, bx11, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   700
    TRANSFORM(im, iu21, iv21, bx22, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   701
    TRANSFORM(im, iu12, iv12, bx11, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   702
    TRANSFORM(im, iu22, iv22, bx22, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   703
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   704
    j2d_glBegin(GL_QUADS);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   705
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, ou11, ov11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   706
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, iu11, iv11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   707
    j2d_glVertex2f(bx11, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   708
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, ou21, ov21);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   709
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, iu21, iv21);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   710
    j2d_glVertex2f(bx22, by11);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   711
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, ou22, ov22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   712
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, iu22, iv22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   713
    j2d_glVertex2f(bx22, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   714
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, ou12, ov12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   715
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, iu12, iv12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   716
    j2d_glVertex2f(bx11, by22);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   717
    j2d_glEnd();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   718
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   719
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   720
void
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   721
OGLRenderer_DrawAAParallelogram(OGLContext *oglc, OGLSDOps *dstOps,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   722
                                jfloat fx11, jfloat fy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   723
                                jfloat dx21, jfloat dy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   724
                                jfloat dx12, jfloat dy12,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   725
                                jfloat lwr21, jfloat lwr12)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   726
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   727
    // dx,dy for line width in the "21" and "12" directions.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   728
    jfloat ldx21, ldy21, ldx12, ldy12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   729
    // parameters for "outer" parallelogram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   730
    jfloat ofx11, ofy11, odx21, ody21, odx12, ody12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   731
    // parameters for "inner" parallelogram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   732
    jfloat ifx11, ify11, idx21, idy21, idx12, idy12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   733
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   734
    J2dTraceLn8(J2D_TRACE_INFO,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   735
                "OGLRenderer_DrawAAParallelogram "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   736
                "(x=%6.2f y=%6.2f "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   737
                "dx1=%6.2f dy1=%6.2f lwr1=%6.2f "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   738
                "dx2=%6.2f dy2=%6.2f lwr2=%6.2f)",
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   739
                fx11, fy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   740
                dx21, dy21, lwr21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   741
                dx12, dy12, lwr12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   742
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   743
    RETURN_IF_NULL(oglc);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   744
    RETURN_IF_NULL(dstOps);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   745
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   746
    // calculate true dx,dy for line widths from the "line width ratios"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   747
    ldx21 = dx21 * lwr21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   748
    ldy21 = dy21 * lwr21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   749
    ldx12 = dx12 * lwr12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   750
    ldy12 = dy12 * lwr12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   751
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   752
    // calculate coordinates of the outer parallelogram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   753
    ofx11 = fx11 - (ldx21 + ldx12) / 2.0f;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   754
    ofy11 = fy11 - (ldy21 + ldy12) / 2.0f;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   755
    odx21 = dx21 + ldx21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   756
    ody21 = dy21 + ldy21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   757
    odx12 = dx12 + ldx12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   758
    ody12 = dy12 + ldy12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   759
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   760
    // Only process the inner parallelogram if the line width ratio
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   761
    // did not consume the entire interior of the parallelogram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   762
    // (i.e. if the width ratio was less than 1.0)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   763
    if (lwr21 < 1.0f && lwr12 < 1.0f) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   764
        // calculate coordinates of the inner parallelogram
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   765
        ifx11 = fx11 + (ldx21 + ldx12) / 2.0f;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   766
        ify11 = fy11 + (ldy21 + ldy12) / 2.0f;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   767
        idx21 = dx21 - ldx21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   768
        idy21 = dy21 - ldy21;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   769
        idx12 = dx12 - ldx12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   770
        idy12 = dy12 - ldy12;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   771
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   772
        OGLRenderer_FillAAParallelogramInnerOuter(oglc, dstOps,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   773
                                                  ofx11, ofy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   774
                                                  odx21, ody21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   775
                                                  odx12, ody12,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   776
                                                  ifx11, ify11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   777
                                                  idx21, idy21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   778
                                                  idx12, idy12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   779
    } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   780
        OGLRenderer_FillAAParallelogram(oglc, dstOps,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   781
                                        ofx11, ofy11,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   782
                                        odx21, ody21,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   783
                                        odx12, ody12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   784
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   785
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   786
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   787
void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   788
OGLRenderer_EnableAAParallelogramProgram(void)
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   789
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   790
    J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_EnableAAParallelogramProgram");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   791
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   792
    if (aaPgramProgram == 0) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   793
        aaPgramProgram = OGLContext_CreateFragmentProgram(aaPgramShaderSource);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   794
        if (aaPgramProgram == 0) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   795
            J2dRlsTraceLn(J2D_TRACE_ERROR,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   796
                          "OGLRenderer_EnableAAParallelogramProgram: "
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   797
                          "error creating program");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   798
            return;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   799
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   800
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   801
    j2d_glUseProgramObjectARB(aaPgramProgram);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   802
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   803
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   804
void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   805
OGLRenderer_DisableAAParallelogramProgram(void)
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   806
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   807
    J2dTraceLn(J2D_TRACE_INFO, "OGLRenderer_DisableAAParallelogramProgram");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   808
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   809
    j2d_glUseProgramObjectARB(0);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   810
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   811
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
#endif /* !HEADLESS */