src/java.desktop/share/native/common/java2d/opengl/OGLVertexCache.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
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 12652
diff changeset
     2
 * Copyright (c) 2007, 2012, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "sun_java2d_SunGraphics2D.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "OGLPaints.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "OGLVertexCache.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
typedef struct _J2DVertex {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    jfloat tx, ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    jubyte r, g, b, a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    jfloat dx, dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
} J2DVertex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
static J2DVertex *vertexCache = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
static jint vertexCacheIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
static GLuint maskCacheTexID = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
static jint maskCacheIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define OGLVC_ADD_VERTEX(TX, TY, R, G, B, A, DX, DY) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        J2DVertex *v = &vertexCache[vertexCacheIndex++]; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        v->tx = TX; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        v->ty = TY; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        v->r  = R;  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        v->g  = G;  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        v->b  = B;  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        v->a  = A;  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        v->dx = DX; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        v->dy = DY; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#define OGLVC_ADD_QUAD(TX1, TY1, TX2, TY2, DX1, DY1, DX2, DY2, R, G, B, A) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        OGLVC_ADD_VERTEX(TX1, TY1, R, G, B, A, DX1, DY1); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        OGLVC_ADD_VERTEX(TX2, TY1, R, G, B, A, DX2, DY1); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        OGLVC_ADD_VERTEX(TX2, TY2, R, G, B, A, DX2, DY2); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        OGLVC_ADD_VERTEX(TX1, TY2, R, G, B, A, DX1, DY2); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
jboolean
12652
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    70
OGLVertexCache_InitVertexCache(OGLContext *oglc)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_InitVertexCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    if (vertexCache == NULL) {
12652
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    75
        vertexCache = (J2DVertex *)malloc(OGLVC_MAX_INDEX * sizeof(J2DVertex));
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    76
        if (vertexCache == NULL) {
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    77
            return JNI_FALSE;
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    78
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
12652
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    81
    if (!oglc->vertexCacheEnabled) {
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    82
        j2d_glTexCoordPointer(2, GL_FLOAT,
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    83
                              sizeof(J2DVertex), vertexCache);
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    84
        j2d_glColorPointer(4, GL_UNSIGNED_BYTE,
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    85
                           sizeof(J2DVertex), ((jfloat *)vertexCache) + 2);
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    86
        j2d_glVertexPointer(2, GL_FLOAT,
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    87
                            sizeof(J2DVertex), ((jfloat *)vertexCache) + 3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
12652
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    89
        j2d_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    90
        j2d_glEnableClientState(GL_COLOR_ARRAY);
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    91
        j2d_glEnableClientState(GL_VERTEX_ARRAY);
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    92
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    93
        oglc->vertexCacheEnabled = JNI_TRUE;
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
    94
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   100
OGLVertexCache_FlushVertexCache(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_FlushVertexCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    if (vertexCacheIndex > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        j2d_glDrawArrays(GL_QUADS, 0, vertexCacheIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    vertexCacheIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * This method is somewhat hacky, but necessary for the foreseeable future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * The problem is the way OpenGL handles color values in vertex arrays.  When
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * a vertex in a vertex array contains a color, and then the vertex array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * is rendered via glDrawArrays(), the global OpenGL color state is actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * modified each time a vertex is rendered.  This means that after all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * vertices have been flushed, the global OpenGL color state will be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * the color of the most recently rendered element in the vertex array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * The reason this is a problem for us is that we do not want to flush the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * vertex array (in the case of mask/glyph operations) or issue a glEnd()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * (in the case of non-antialiased primitives) everytime the current color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * changes, which would defeat any benefit from batching in the first place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * We handle this in practice by not calling CHECK/RESET_PREVIOUS_OP() when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * the simple color state is changing in OGLPaints_SetColor().  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * problematic for vertex caching because we may end up with the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * situation, for example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *   SET_COLOR (orange)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *   MASK_FILL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *   MASK_FILL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *   SET_COLOR (blue; remember, this won't cause a flush)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *   FILL_RECT (this will cause the vertex array to be flushed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * In this case, we would actually end up rendering an orange FILL_RECT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * not a blue one as intended, because flushing the vertex cache flush would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * override the color state from the most recent SET_COLOR call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * Long story short, the easiest way to resolve this problem is to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * this method just after disabling the mask/glyph cache, which will ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * that the appropriate color state is restored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
OGLVertexCache_RestoreColorState(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    if (oglc->paintState == sun_java2d_SunGraphics2D_PAINT_ALPHACOLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        OGLPaints_SetColor(oglc, oglc->pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
static jboolean
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   150
OGLVertexCache_InitMaskCache(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_InitMaskCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    maskCacheTexID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        OGLContext_CreateBlitTexture(GL_INTENSITY8, GL_LUMINANCE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                     OGLVC_MASK_CACHE_WIDTH_IN_TEXELS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                     OGLVC_MASK_CACHE_HEIGHT_IN_TEXELS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    // init special fully opaque tile in the upper-right corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    // the mask cache texture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        GLubyte allOnes[OGLVC_MASK_CACHE_TILE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        memset(allOnes, 0xff, OGLVC_MASK_CACHE_TILE_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        j2d_glTexSubImage2D(GL_TEXTURE_2D, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                            OGLVC_MASK_CACHE_SPECIAL_TILE_X,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                            OGLVC_MASK_CACHE_SPECIAL_TILE_Y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                            OGLVC_MASK_CACHE_TILE_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                            OGLVC_MASK_CACHE_TILE_HEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                            GL_LUMINANCE, GL_UNSIGNED_BYTE, allOnes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
OGLVertexCache_EnableMaskCache(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_EnableMaskCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
12652
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
   180
    if (!OGLVertexCache_InitVertexCache(oglc)) {
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
   181
        return;
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
   182
    }
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 5506
diff changeset
   183
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    if (maskCacheTexID == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (!OGLVertexCache_InitMaskCache()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    j2d_glEnable(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    j2d_glBindTexture(GL_TEXTURE_2D, maskCacheTexID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    OGLC_UPDATE_TEXTURE_FUNCTION(oglc, GL_MODULATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
OGLVertexCache_DisableMaskCache(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_DisableMaskCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    OGLVertexCache_FlushVertexCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    OGLVertexCache_RestoreColorState(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    j2d_glDisable(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    maskCacheIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
OGLVertexCache_AddMaskQuad(OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                           jint srcx, jint srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                           jint dstx, jint dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                           jint width, jint height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                           jint maskscan, void *mask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    jfloat tx1, ty1, tx2, ty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    jfloat dx1, dy1, dx2, dy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    J2dTraceLn1(J2D_TRACE_INFO, "OGLVertexCache_AddMaskQuad: %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                maskCacheIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    if (maskCacheIndex >= OGLVC_MASK_CACHE_MAX_INDEX ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        vertexCacheIndex >= OGLVC_MAX_INDEX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        OGLVertexCache_FlushVertexCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        maskCacheIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    if (mask != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        jint texx = OGLVC_MASK_CACHE_TILE_WIDTH *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            (maskCacheIndex % OGLVC_MASK_CACHE_WIDTH_IN_TILES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        jint texy = OGLVC_MASK_CACHE_TILE_HEIGHT *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            (maskCacheIndex / OGLVC_MASK_CACHE_WIDTH_IN_TILES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // update the source pointer offsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, srcx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, srcy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, maskscan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // copy alpha mask into texture tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        j2d_glTexSubImage2D(GL_TEXTURE_2D, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            texx, texy, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                            GL_LUMINANCE, GL_UNSIGNED_BYTE, mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        tx1 = ((jfloat)texx) / OGLVC_MASK_CACHE_WIDTH_IN_TEXELS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        ty1 = ((jfloat)texy) / OGLVC_MASK_CACHE_HEIGHT_IN_TEXELS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        maskCacheIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        // use special fully opaque tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        tx1 = ((jfloat)OGLVC_MASK_CACHE_SPECIAL_TILE_X) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            OGLVC_MASK_CACHE_WIDTH_IN_TEXELS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        ty1 = ((jfloat)OGLVC_MASK_CACHE_SPECIAL_TILE_Y) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            OGLVC_MASK_CACHE_HEIGHT_IN_TEXELS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    tx2 = tx1 + (((jfloat)width) / OGLVC_MASK_CACHE_WIDTH_IN_TEXELS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    ty2 = ty1 + (((jfloat)height) / OGLVC_MASK_CACHE_HEIGHT_IN_TEXELS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    dx1 = (jfloat)dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    dy1 = (jfloat)dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    dx2 = dx1 + width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    dy2 = dy1 + height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    OGLVC_ADD_QUAD(tx1, ty1, tx2, ty2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                   dx1, dy1, dx2, dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                   oglc->r, oglc->g, oglc->b, oglc->a);
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
OGLVertexCache_AddGlyphQuad(OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                            jfloat tx1, jfloat ty1, jfloat tx2, jfloat ty2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                            jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_AddGlyphQuad");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    if (vertexCacheIndex >= OGLVC_MAX_INDEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        OGLVertexCache_FlushVertexCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    OGLVC_ADD_QUAD(tx1, ty1, tx2, ty2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                   dx1, dy1, dx2, dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                   oglc->r, oglc->g, oglc->b, oglc->a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
#endif /* !HEADLESS */