src/java.desktop/share/native/common/java2d/opengl/OGLContext.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: 18516
diff changeset
     2
 * Copyright (c) 2004, 2013, 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 <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 "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "OGLContext.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "OGLRenderQueue.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "OGLSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "GraphicsPrimitiveMgr.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "Region.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
23304
bb48872f9326 8035287: gcc warnings compiling various libraries files
mikael
parents: 18516
diff changeset
    41
#include "jvm.h"
bb48872f9326 8035287: gcc warnings compiling various libraries files
mikael
parents: 18516
diff changeset
    42
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The following methods are implemented in the windowing system (i.e. GLX
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * and WGL) source files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
extern jboolean OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
extern OGLContext *OGLSD_MakeOGLContextCurrent(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                                               OGLSDOps *srcOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                                               OGLSDOps *dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * This table contains the standard blending rules (or Porter-Duff compositing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * factors) used in glBlendFunc(), indexed by the rule constants from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * AlphaComposite class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
OGLBlendRule StdBlendRules[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    { GL_ZERO,                GL_ZERO                }, /* 0 - Nothing      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    { GL_ZERO,                GL_ZERO                }, /* 1 - RULE_Clear   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    { GL_ONE,                 GL_ZERO                }, /* 2 - RULE_Src     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    { GL_ONE,                 GL_ONE_MINUS_SRC_ALPHA }, /* 3 - RULE_SrcOver */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    { GL_ONE_MINUS_DST_ALPHA, GL_ONE                 }, /* 4 - RULE_DstOver */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    { GL_DST_ALPHA,           GL_ZERO                }, /* 5 - RULE_SrcIn   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    { GL_ZERO,                GL_SRC_ALPHA           }, /* 6 - RULE_DstIn   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    { GL_ONE_MINUS_DST_ALPHA, GL_ZERO                }, /* 7 - RULE_SrcOut  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    { GL_ZERO,                GL_ONE_MINUS_SRC_ALPHA }, /* 8 - RULE_DstOut  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    { GL_ZERO,                GL_ONE                 }, /* 9 - RULE_Dst     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    { GL_DST_ALPHA,           GL_ONE_MINUS_SRC_ALPHA }, /*10 - RULE_SrcAtop */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    { GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA           }, /*11 - RULE_DstAtop */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    { GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, /*12 - RULE_AlphaXor*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
/** Evaluates to "front" or "back", depending on the value of buf. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#define OGLC_ACTIVE_BUFFER_NAME(buf) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    (buf == GL_FRONT || buf == GL_COLOR_ATTACHMENT0_EXT) ? "front" : "back"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Initializes the viewport and projection matrix, effectively positioning
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * the origin at the top-left corner of the surface.  This allows Java 2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * coordinates to be passed directly to OpenGL, which is typically based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * a bottom-right coordinate system.  This method also sets the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * read and draw buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
OGLContext_SetViewport(OGLSDOps *srcOps, OGLSDOps *dstOps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    jint width = dstOps->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    jint height = dstOps->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    J2dTraceLn4(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                "OGLContext_SetViewport: w=%d h=%d read=%s draw=%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                OGLC_ACTIVE_BUFFER_NAME(srcOps->activeBuffer),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                OGLC_ACTIVE_BUFFER_NAME(dstOps->activeBuffer));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // set the viewport and projection matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    j2d_glViewport(dstOps->xOffset, dstOps->yOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                   (GLsizei)width, (GLsizei)height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    j2d_glMatrixMode(GL_PROJECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    j2d_glLoadIdentity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    j2d_glOrtho(0.0, (GLdouble)width, (GLdouble)height, 0.0, -1.0, 1.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // set the active read and draw buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    j2d_glReadBuffer(srcOps->activeBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    j2d_glDrawBuffer(dstOps->activeBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // set the color mask to enable alpha channel only when necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    j2d_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, (GLboolean)!dstOps->isOpaque);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * Initializes the alpha channel of the current surface so that it contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * fully opaque alpha values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
static void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   116
OGLContext_InitAlphaChannel(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    GLboolean scissorEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_InitAlphaChannel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // it is possible for the scissor test to be enabled at this point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    // if it is, disable it temporarily since it can affect the glClear() op
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    scissorEnabled = j2d_glIsEnabled(GL_SCISSOR_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    if (scissorEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        j2d_glDisable(GL_SCISSOR_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    // set the color mask so that we only affect the alpha channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    j2d_glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // clear the color buffer so that the alpha channel is fully opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    j2d_glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    j2d_glClear(GL_COLOR_BUFFER_BIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    // restore the color mask (as it was set in OGLContext_SetViewport())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    j2d_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    // re-enable scissor test, only if it was enabled earlier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    if (scissorEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        j2d_glEnable(GL_SCISSOR_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * Fetches the OGLContext associated with the given destination surface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * makes the context current for those surfaces, updates the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * viewport, and then returns a pointer to the OGLContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
OGLContext *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
OGLContext_SetSurfaces(JNIEnv *env, jlong pSrc, jlong pDst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    OGLSDOps *srcOps = (OGLSDOps *)jlong_to_ptr(pSrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    OGLSDOps *dstOps = (OGLSDOps *)jlong_to_ptr(pDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    OGLContext *oglc = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_SetSurfaces");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    if (srcOps == NULL || dstOps == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            "OGLContext_SetSurfaces: ops are null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    J2dTraceLn2(J2D_TRACE_VERBOSE, "  srctype=%d dsttype=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                srcOps->drawableType, dstOps->drawableType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    if (dstOps->drawableType == OGLSD_TEXTURE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            "OGLContext_SetSurfaces: texture cannot be used as destination");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    if (dstOps->drawableType == OGLSD_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // initialize the surface as an OGLSD_WINDOW
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (!OGLSD_InitOGLWindow(env, dstOps)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                "OGLContext_SetSurfaces: could not init OGL window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    // make the context current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    oglc = OGLSD_MakeOGLContextCurrent(env, srcOps, dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    if (oglc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            "OGLContext_SetSurfaces: could not make context current");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    // update the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    OGLContext_SetViewport(srcOps, dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    // perform additional one-time initialization, if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    if (dstOps->needsInit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (dstOps->isOpaque) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // in this case we are treating the destination as opaque, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            // to do so, first we need to ensure that the alpha channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            // is filled with fully opaque values (see 6319663)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            OGLContext_InitAlphaChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        dstOps->needsInit = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    return oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * Resets the current clip state (disables both scissor and depth tests).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
OGLContext_ResetClip(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_ResetClip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    CHECK_PREVIOUS_OP(OGL_STATE_CHANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    j2d_glDisable(GL_SCISSOR_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    j2d_glDisable(GL_DEPTH_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * Sets the OpenGL scissor bounds to the provided rectangular clip bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
OGLContext_SetRectClip(OGLContext *oglc, OGLSDOps *dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                       jint x1, jint y1, jint x2, jint y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    jint width = x2 - x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    jint height = y2 - y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    J2dTraceLn4(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                "OGLContext_SetRectClip: x=%d y=%d w=%d h=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                x1, y1, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    RETURN_IF_NULL(dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    CHECK_PREVIOUS_OP(OGL_STATE_CHANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    if ((width < 0) || (height < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        // use an empty scissor rectangle when the region is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    j2d_glDisable(GL_DEPTH_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    j2d_glEnable(GL_SCISSOR_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    // the scissor rectangle is specified using the lower-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    // origin of the clip region (in the framebuffer's coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    // space), so we must account for the x/y offsets of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    // destination surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    j2d_glScissor(dstOps->xOffset + x1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                  dstOps->yOffset + dstOps->height - (y1 + height),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                  width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * Sets up a complex (shape) clip using the OpenGL depth buffer.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 * method prepares the depth buffer so that the clip Region spans can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * be "rendered" into it.  The depth buffer is first cleared, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * depth func is setup so that when we render the clip spans,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * nothing is rendered into the color buffer, but for each pixel that would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * be rendered, a non-zero value is placed into that location in the depth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * buffer.  With depth test enabled, pixels will only be rendered into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * color buffer if the corresponding value at that (x,y) location in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * depth buffer differs from the incoming depth value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
OGLContext_BeginShapeClip(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_BeginShapeClip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    RESET_PREVIOUS_OP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    j2d_glDisable(GL_SCISSOR_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    // enable depth test and clear depth buffer so that depth values are at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    // their maximum; also set the depth func to GL_ALWAYS so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    // depth values of the clip spans are forced into the depth buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    j2d_glEnable(GL_DEPTH_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    j2d_glClearDepth(1.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    j2d_glClear(GL_DEPTH_BUFFER_BIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    j2d_glDepthFunc(GL_ALWAYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    // disable writes into the color buffer while we set up the clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    j2d_glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    // save current transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    j2d_glMatrixMode(GL_MODELVIEW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    j2d_glPushMatrix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    // use identity transform plus slight translation in the z-axis when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    // setting the clip spans; this will push the clip spans (which would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    // normally be at z=0) to the z=1 plane to give them some depth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    j2d_glLoadIdentity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    j2d_glTranslatef(0.0f, 0.0f, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * Finishes setting up the shape clip by resetting the depth func
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * so that future rendering operations will once again be written into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 * color buffer (while respecting the clip set up in the depth buffer).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
OGLContext_EndShapeClip(OGLContext *oglc, OGLSDOps *dstOps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_EndShapeClip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    RETURN_IF_NULL(dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    RESET_PREVIOUS_OP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    // restore transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    j2d_glPopMatrix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    // re-enable writes into the color buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    j2d_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, (GLboolean)!dstOps->isOpaque);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    // enable the depth test so that only fragments within the clip region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    // (i.e. those fragments whose z-values are >= the values currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    // stored in the depth buffer) are rendered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    j2d_glDepthFunc(GL_GEQUAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 * Initializes the OpenGL state responsible for applying extra alpha.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 * step is only necessary for any operation that uses glDrawPixels() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 * glCopyPixels() with a non-1.0f extra alpha value.  Since the source is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 * always premultiplied, we apply the extra alpha value to both alpha and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 * color components using GL_*_SCALE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
OGLContext_SetExtraAlpha(jfloat ea)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    J2dTraceLn1(J2D_TRACE_INFO, "OGLContext_SetExtraAlpha: ea=%f", ea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    j2d_glPixelTransferf(GL_ALPHA_SCALE, ea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    j2d_glPixelTransferf(GL_RED_SCALE, ea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    j2d_glPixelTransferf(GL_GREEN_SCALE, ea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    j2d_glPixelTransferf(GL_BLUE_SCALE, ea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
 * Resets all OpenGL compositing state (disables blending and logic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
 * operations).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
OGLContext_ResetComposite(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_ResetComposite");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    CHECK_PREVIOUS_OP(OGL_STATE_CHANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    // disable blending and XOR mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    if (oglc->compState == sun_java2d_SunGraphics2D_COMP_ALPHA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        j2d_glDisable(GL_BLEND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    } else if (oglc->compState == sun_java2d_SunGraphics2D_COMP_XOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        j2d_glDisable(GL_COLOR_LOGIC_OP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        j2d_glDisable(GL_ALPHA_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    // set state to default values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    oglc->compState = sun_java2d_SunGraphics2D_COMP_ISCOPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    oglc->extraAlpha = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
 * Initializes the OpenGL blending state.  XOR mode is disabled and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
 * appropriate blend functions are setup based on the AlphaComposite rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
 * constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
OGLContext_SetAlphaComposite(OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                             jint rule, jfloat extraAlpha, jint flags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    J2dTraceLn1(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                "OGLContext_SetAlphaComposite: flags=%d", flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    CHECK_PREVIOUS_OP(OGL_STATE_CHANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    // disable XOR mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    if (oglc->compState == sun_java2d_SunGraphics2D_COMP_XOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        j2d_glDisable(GL_COLOR_LOGIC_OP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        j2d_glDisable(GL_ALPHA_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    // we can safely disable blending when:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    //   - comp is SrcNoEa or SrcOverNoEa, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    //   - the source is opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    // (turning off blending can have a large positive impact on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    // performance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    if ((rule == RULE_Src || rule == RULE_SrcOver) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        (extraAlpha == 1.0f) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        (flags & OGLC_SRC_IS_OPAQUE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        J2dTraceLn1(J2D_TRACE_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    "  disabling alpha comp: rule=%d ea=1.0 src=opq", rule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        j2d_glDisable(GL_BLEND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        J2dTraceLn2(J2D_TRACE_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    "  enabling alpha comp: rule=%d ea=%f", rule, extraAlpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        j2d_glEnable(GL_BLEND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        j2d_glBlendFunc(StdBlendRules[rule].src, StdBlendRules[rule].dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    // update state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    oglc->compState = sun_java2d_SunGraphics2D_COMP_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    oglc->extraAlpha = extraAlpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
 * Initializes the OpenGL logic op state to XOR mode.  Blending is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
 * before enabling logic op mode.  The XOR pixel value will be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
 * later in the OGLContext_SetColor() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
OGLContext_SetXorComposite(OGLContext *oglc, jint xorPixel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    J2dTraceLn1(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                "OGLContext_SetXorComposite: xorPixel=%08x", xorPixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    CHECK_PREVIOUS_OP(OGL_STATE_CHANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    // disable blending mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    if (oglc->compState == sun_java2d_SunGraphics2D_COMP_ALPHA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        j2d_glDisable(GL_BLEND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    // enable XOR mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    j2d_glEnable(GL_COLOR_LOGIC_OP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    j2d_glLogicOp(GL_XOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    // set up the alpha test so that we discard transparent fragments (this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    // is primarily useful for rendering text in XOR mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    j2d_glEnable(GL_ALPHA_TEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    j2d_glAlphaFunc(GL_NOTEQUAL, 0.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    // update state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    oglc->compState = sun_java2d_SunGraphics2D_COMP_XOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    oglc->xorPixel = xorPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    oglc->extraAlpha = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
 * Resets the OpenGL transform state back to the identity matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
OGLContext_ResetTransform(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_ResetTransform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    CHECK_PREVIOUS_OP(OGL_STATE_CHANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    j2d_glMatrixMode(GL_MODELVIEW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    j2d_glLoadIdentity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 * Initializes the OpenGL transform state by setting the modelview transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
 * using the given matrix parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
 * REMIND: it may be worthwhile to add serial id to AffineTransform, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
 *         could do a quick check to see if the xform has changed since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
 *         last time... a simple object compare won't suffice...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
OGLContext_SetTransform(OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                        jdouble m00, jdouble m10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        jdouble m01, jdouble m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        jdouble m02, jdouble m12)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_SetTransform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    CHECK_PREVIOUS_OP(OGL_STATE_CHANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    if (oglc->xformMatrix == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        size_t arrsize = 16 * sizeof(GLdouble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        oglc->xformMatrix = (GLdouble *)malloc(arrsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        memset(oglc->xformMatrix, 0, arrsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        oglc->xformMatrix[10] = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        oglc->xformMatrix[15] = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    // copy values from AffineTransform object into native matrix array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    oglc->xformMatrix[0] = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    oglc->xformMatrix[1] = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    oglc->xformMatrix[4] = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    oglc->xformMatrix[5] = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    oglc->xformMatrix[12] = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    oglc->xformMatrix[13] = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    J2dTraceLn3(J2D_TRACE_VERBOSE, "  [%lf %lf %lf]",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                oglc->xformMatrix[0], oglc->xformMatrix[4],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                oglc->xformMatrix[12]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    J2dTraceLn3(J2D_TRACE_VERBOSE, "  [%lf %lf %lf]",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                oglc->xformMatrix[1], oglc->xformMatrix[5],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                oglc->xformMatrix[13]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    j2d_glMatrixMode(GL_MODELVIEW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    j2d_glLoadMatrixd(oglc->xformMatrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
 * Creates a 2D texture of the given format and dimensions and returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
 * texture object identifier.  This method is typically used to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
 * temporary texture for intermediate work, such as in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
 * OGLContext_InitBlitTileTexture() method below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
GLuint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
OGLContext_CreateBlitTexture(GLenum internalFormat, GLenum pixelFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                             GLuint width, GLuint height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    GLuint texID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    GLint sp, sr, rl, align;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    GLclampf priority = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_CreateBlitTexture");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    j2d_glGenTextures(1, &texID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    j2d_glBindTexture(GL_TEXTURE_2D, texID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    j2d_glPrioritizeTextures(1, &texID, &priority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    OGLSD_RESET_TEXTURE_WRAP(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    // save pixel store parameters (since this method could be invoked after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    // the caller has already set up its pixel store parameters)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    j2d_glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    j2d_glGetIntegerv(GL_UNPACK_SKIP_ROWS, &sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    j2d_glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    j2d_glGetIntegerv(GL_UNPACK_ALIGNMENT, &align);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    // set pixel store parameters to default values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    j2d_glTexImage2D(GL_TEXTURE_2D, 0, internalFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                     width, height, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                     pixelFormat, GL_UNSIGNED_BYTE, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    // restore pixel store parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, rl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, align);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    return texID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
 * Initializes a small texture tile for use with tiled blit operations (see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
 * OGLBlitLoops.c and OGLMaskBlit.c for usage examples).  The texture ID for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
 * the tile is stored in the given OGLContext.  The tile is initially filled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
 * with garbage values, but the tile is updated as needed (via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
 * glTexSubImage2D()) with real RGBA values used in tiled blit situations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
 * The internal format for the texture is GL_RGBA8, which should be sufficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
 * for storing system memory surfaces of any known format (see PixelFormats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
 * for a list of compatible surface formats).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
OGLContext_InitBlitTileTexture(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_InitBlitTileTexture");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    oglc->blitTextureID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        OGLContext_CreateBlitTexture(GL_RGBA8, GL_RGBA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                     OGLC_BLIT_TILE_SIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                                     OGLC_BLIT_TILE_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
 * Destroys the OpenGL resources associated with the given OGLContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
 * It is required that the native context associated with the OGLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
 * be made current prior to calling this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
OGLContext_DestroyContextResources(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_DestroyContextResources");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    if (oglc->xformMatrix != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        free(oglc->xformMatrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    if (oglc->blitTextureID != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        j2d_glDeleteTextures(1, &oglc->blitTextureID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
 * Returns JNI_TRUE if the given extension name is available for the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
 * GraphicsConfig; JNI_FALSE otherwise.  An extension is considered available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
 * if its identifier string is found amongst the space-delimited GL_EXTENSIONS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
 * string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
 * Adapted from the OpenGL Red Book, pg. 506.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
OGLContext_IsExtensionAvailable(const char *extString, char *extName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    jboolean ret = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    char *p = (char *)extString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    char *end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    if (extString == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        J2dTraceLn(J2D_TRACE_INFO, "OGLContext_IsExtensionAvailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            "OGLContext_IsExtensionAvailable: extension string is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    end = p + strlen(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    while (p < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        size_t n = strcspn(p, " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        if ((strlen(extName) == n) && (strncmp(extName, p, n) == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            ret = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        p += (n + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    J2dRlsTraceLn2(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                   "OGLContext_IsExtensionAvailable: %s=%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                   extName, ret ? "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
 * Returns JNI_TRUE only if all of the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
 *   - the GL_EXT_framebuffer_object extension is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
 *   - FBO support has been enabled via the system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
 *   - we can successfully create an FBO with depth capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
OGLContext_IsFBObjectExtensionAvailable(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                                        const char *extString)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    jboolean isFBObjectEnabled = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    GLuint fbobjectID, textureID, depthID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    jint width = 1, height = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_IsFBObjectExtensionAvailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    // first see if the fbobject extension is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    if (!OGLContext_IsExtensionAvailable(extString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                                         "GL_EXT_framebuffer_object"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
18516
1f7d58c5f2e7 8016254: several sun/java2d/OpenGL tests failed with SIGFPE
vadim
parents: 5506
diff changeset
   667
    // next see if the depth texture extension is available
1f7d58c5f2e7 8016254: several sun/java2d/OpenGL tests failed with SIGFPE
vadim
parents: 5506
diff changeset
   668
    if (!OGLContext_IsExtensionAvailable(extString,
1f7d58c5f2e7 8016254: several sun/java2d/OpenGL tests failed with SIGFPE
vadim
parents: 5506
diff changeset
   669
                                         "GL_ARB_depth_texture"))
1f7d58c5f2e7 8016254: several sun/java2d/OpenGL tests failed with SIGFPE
vadim
parents: 5506
diff changeset
   670
    {
1f7d58c5f2e7 8016254: several sun/java2d/OpenGL tests failed with SIGFPE
vadim
parents: 5506
diff changeset
   671
        return JNI_FALSE;
1f7d58c5f2e7 8016254: several sun/java2d/OpenGL tests failed with SIGFPE
vadim
parents: 5506
diff changeset
   672
    }
1f7d58c5f2e7 8016254: several sun/java2d/OpenGL tests failed with SIGFPE
vadim
parents: 5506
diff changeset
   673
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    // next see if the fbobject system property has been enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    isFBObjectEnabled =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        JNU_GetStaticFieldByName(env, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                                 "sun/java2d/opengl/OGLSurfaceData",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                                 "isFBObjectEnabled", "Z").z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    if (!isFBObjectEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        J2dRlsTraceLn(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            "OGLContext_IsFBObjectExtensionAvailable: disabled via flag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    // finally, create a dummy fbobject with depth capabilities to see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    // if this configuration is supported by the drivers/hardware
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    // (first we initialize a color texture object that will be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    // construct the dummy fbobject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    j2d_glGenTextures(1, &textureID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    j2d_glBindTexture(GL_TEXTURE_2D, textureID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    j2d_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                     width, height, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                     GL_RGB, GL_UNSIGNED_BYTE, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    // initialize framebuffer object using color texture created above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    if (!OGLSD_InitFBObject(&fbobjectID, &depthID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                            textureID, GL_TEXTURE_2D,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                            width, height))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        J2dRlsTraceLn(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            "OGLContext_IsFBObjectExtensionAvailable: fbobject unsupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        j2d_glDeleteTextures(1, &textureID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    // delete the temporary resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    j2d_glDeleteTextures(1, &textureID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    j2d_glDeleteRenderbuffersEXT(1, &depthID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    j2d_glDeleteFramebuffersEXT(1, &fbobjectID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    J2dRlsTraceLn(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        "OGLContext_IsFBObjectExtensionAvailable: fbobject supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
 * Returns JNI_TRUE only if all of the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
 *   - the GL_ARB_fragment_shader extension is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
 *   - the LCD text shader codepath has been enabled via the system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
 *   - the hardware supports the minimum number of texture units
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
OGLContext_IsLCDShaderSupportAvailable(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                                       jboolean fragShaderAvailable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    jboolean isLCDShaderEnabled = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    GLint maxTexUnits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_IsLCDShaderSupportAvailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    // first see if the fragment shader extension is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    if (!fragShaderAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    // next see if the lcdshader system property has been enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    isLCDShaderEnabled =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        JNU_GetStaticFieldByName(env, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                                 "sun/java2d/opengl/OGLSurfaceData",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                 "isLCDShaderEnabled", "Z").z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    if (!isLCDShaderEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        J2dRlsTraceLn(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            "OGLContext_IsLCDShaderSupportAvailable: disabled via flag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    // finally, check to see if the hardware supports the required number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    // of texture units
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    j2d_glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &maxTexUnits);
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 28076
diff changeset
   753
    if (maxTexUnits < 2) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        J2dRlsTraceLn1(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
          "OGLContext_IsLCDShaderSupportAvailable: not enough tex units (%d)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
          maxTexUnits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    J2dRlsTraceLn(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        "OGLContext_IsLCDShaderSupportAvailable: LCD text shader supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
 * Returns JNI_TRUE only if all of the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
 *   - the GL_ARB_fragment_shader extension is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
 *   - the BufferedImageOp shader codepath has been enabled via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
 *     system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
OGLContext_IsBIOpShaderSupportAvailable(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                                        jboolean fragShaderAvailable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    jboolean isBIOpShaderEnabled = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_IsBIOpShaderSupportAvailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    // first see if the fragment shader extension is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    if (!fragShaderAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    // next see if the biopshader system property has been enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    isBIOpShaderEnabled =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        JNU_GetStaticFieldByName(env, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                                 "sun/java2d/opengl/OGLSurfaceData",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                                 "isBIOpShaderEnabled", "Z").z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    if (!isBIOpShaderEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        J2dRlsTraceLn(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            "OGLContext_IsBIOpShaderSupportAvailable: disabled via flag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * Note: In theory we should probably do some other checks here, like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * linking a sample shader to see if the hardware truly supports our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * shader programs.  However, our current BufferedImageOp shaders were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * designed to support first-generation shader-level hardware, so the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * assumption is that if our shaders work on those GPUs, then they'll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * work on newer ones as well.  Also, linking a fragment program can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * cost valuable CPU cycles, which is another reason to avoid these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * checks at startup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    J2dRlsTraceLn(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        "OGLContext_IsBIOpShaderSupportAvailable: BufferedImageOp shader supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
 * Returns JNI_TRUE only if all of the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
 *   - the GL_ARB_fragment_shader extension is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
 *   - the Linear/RadialGradientPaint shader codepath has been enabled via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
 *     system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
OGLContext_IsGradShaderSupportAvailable(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                                        jboolean fragShaderAvailable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    jboolean isGradShaderEnabled = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_IsGradShaderSupportAvailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    // first see if the fragment shader extension is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    if (!fragShaderAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    // next see if the gradshader system property has been enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    isGradShaderEnabled =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        JNU_GetStaticFieldByName(env, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                                 "sun/java2d/opengl/OGLSurfaceData",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                                 "isGradShaderEnabled", "Z").z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    if (!isGradShaderEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        J2dRlsTraceLn(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            "OGLContext_IsGradShaderSupportAvailable: disabled via flag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    J2dRlsTraceLn(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        "OGLContext_IsGradShaderSupportAvailable: Linear/RadialGradientPaint shader supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
 * Checks for the presence of the optional extensions used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
 * the Java 2D OpenGL pipeline.  The given caps bitfield is updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
 * to reflect the availability of these extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
OGLContext_GetExtensionInfo(JNIEnv *env, jint *caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    jint vcap = OGLC_VENDOR_OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    const char *vendor = (char *)j2d_glGetString(GL_VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    const char *e = (char *)j2d_glGetString(GL_EXTENSIONS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    jboolean fragShaderAvail =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        OGLContext_IsExtensionAvailable(e, "GL_ARB_fragment_shader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_GetExtensionInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   864
    *caps |= CAPS_TEXNONSQUARE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    if (OGLContext_IsExtensionAvailable(e, "GL_ARB_multitexture")) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   866
        *caps |= CAPS_MULTITEXTURE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    if (OGLContext_IsExtensionAvailable(e, "GL_ARB_texture_non_power_of_two")){
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   869
        *caps |= CAPS_TEXNONPOW2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   871
    // 6656574: Use of the GL_ARB_texture_rectangle extension by Java 2D
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   872
    // complicates any third-party libraries that try to interact with
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   873
    // the OGL pipeline (and we've run into driver bugs in the past related
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   874
    // to this extension), so for now we will disable its use by default (unless
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   875
    // forced). We will still make use of the GL_ARB_texture_non_power_of_two
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   876
    // extension when available, which is the better choice going forward
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   877
    // anyway.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   878
    if (OGLContext_IsExtensionAvailable(e, "GL_ARB_texture_rectangle") &&
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   879
        getenv("J2D_OGL_TEXRECT") != NULL)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   880
    {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   881
        *caps |= CAPS_EXT_TEXRECT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    if (OGLContext_IsFBObjectExtensionAvailable(env, e)) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   884
        *caps |= CAPS_EXT_FBOBJECT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    if (OGLContext_IsLCDShaderSupportAvailable(env, fragShaderAvail)) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   887
        *caps |= CAPS_EXT_LCD_SHADER | CAPS_PS20;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    if (OGLContext_IsBIOpShaderSupportAvailable(env, fragShaderAvail)) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   890
        *caps |= CAPS_EXT_BIOP_SHADER | CAPS_PS20;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    if (OGLContext_IsGradShaderSupportAvailable(env, fragShaderAvail)) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   893
        *caps |= CAPS_EXT_GRAD_SHADER | CAPS_PS20;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   895
    if (OGLContext_IsExtensionAvailable(e, "GL_NV_fragment_program")) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   896
        // this is an Nvidia board, at least PS 2.0, but we can't
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   897
        // use the "max instructions" heuristic since GeForce FX
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   898
        // boards report 1024 even though they're only PS 2.0,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   899
        // so we'll check the following, which does imply PS 3.0
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   900
        if (OGLContext_IsExtensionAvailable(e, "GL_NV_fragment_program2")) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   901
            *caps |= CAPS_PS30;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   902
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   903
    } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   904
        // for all other boards, we look at the "max instructions"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   905
        // count reported by the GL_ARB_fragment_program extension
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   906
        // as a heuristic for detecting PS 3.0 compatible hardware
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   907
        if (OGLContext_IsExtensionAvailable(e, "GL_ARB_fragment_program")) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   908
            GLint instr;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   909
            j2d_glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   910
                                  GL_MAX_PROGRAM_INSTRUCTIONS_ARB, &instr);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   911
            if (instr > 512) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   912
                *caps |= CAPS_PS30;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   913
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   914
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   915
    }
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31158
diff changeset
   916
    if (OGLContext_IsExtensionAvailable(e, "GL_NV_texture_barrier")) {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31158
diff changeset
   917
        *caps |= CAPS_EXT_TEXBARRIER;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31158
diff changeset
   918
    }
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31158
diff changeset
   919
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    // stuff vendor descriptor in the upper bits of the caps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    if (vendor != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        if (strncmp(vendor, "ATI", 3) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            vcap = OGLC_VENDOR_ATI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        } else if (strncmp(vendor, "NVIDIA", 6) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            vcap = OGLC_VENDOR_NVIDIA;
28076
64c048b63cea 8059944: [OGL] Metrics for a method choice copying of texture should be improved
serb
parents: 26751
diff changeset
   926
        } else if (strncmp(vendor, "Intel", 5) == 0) {
64c048b63cea 8059944: [OGL] Metrics for a method choice copying of texture should be improved
serb
parents: 26751
diff changeset
   927
            vcap = OGLC_VENDOR_INTEL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   929
        // REMIND: new in 7 - check if needs fixing
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   930
        *caps |= ((vcap & OGLC_VCAP_MASK) << OGLC_VCAP_OFFSET);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   932
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
 * Returns JNI_TRUE if the given GL_VERSION string meets the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
 * requirements (>= 1.2); JNI_FALSE otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
OGLContext_IsVersionSupported(const unsigned char *versionstr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_IsVersionSupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    if (versionstr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            "OGLContext_IsVersionSupported: version string is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    // note that this check allows for OpenGL 2.x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    return ((versionstr[0] == '1' && versionstr[2] >= '2') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            (versionstr[0] >= '2'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
 * Compiles and links the given fragment shader program.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
 * successful, this function returns a handle to the newly created shader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
 * program; otherwise returns 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
GLhandleARB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
OGLContext_CreateFragmentProgram(const char *fragmentShaderSource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    GLhandleARB fragmentShader, fragmentProgram;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    GLint success;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    int infoLogLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_CreateFragmentProgram");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    // create the shader object and compile the shader source code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    fragmentShader = j2d_glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    j2d_glShaderSourceARB(fragmentShader, 1, &fragmentShaderSource, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    j2d_glCompileShaderARB(fragmentShader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    j2d_glGetObjectParameterivARB(fragmentShader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                                  GL_OBJECT_COMPILE_STATUS_ARB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                                  &success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    // print the compiler messages, if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    j2d_glGetObjectParameterivARB(fragmentShader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                                  GL_OBJECT_INFO_LOG_LENGTH_ARB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                                  &infoLogLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    if (infoLogLength > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        char infoLog[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        j2d_glGetInfoLogARB(fragmentShader, 1024, NULL, infoLog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        J2dRlsTraceLn2(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            "OGLContext_CreateFragmentProgram: compiler msg (%d):\n%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                       infoLogLength, infoLog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    if (!success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            "OGLContext_CreateFragmentProgram: error compiling shader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        j2d_glDeleteObjectARB(fragmentShader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    // create the program object and attach it to the shader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    fragmentProgram = j2d_glCreateProgramObjectARB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    j2d_glAttachObjectARB(fragmentProgram, fragmentShader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    // it is now safe to delete the shader object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    j2d_glDeleteObjectARB(fragmentShader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    // link the program
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    j2d_glLinkProgramARB(fragmentProgram);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    j2d_glGetObjectParameterivARB(fragmentProgram,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                                  GL_OBJECT_LINK_STATUS_ARB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                                  &success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    // print the linker messages, if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    j2d_glGetObjectParameterivARB(fragmentProgram,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                                  GL_OBJECT_INFO_LOG_LENGTH_ARB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                                  &infoLogLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    if (infoLogLength > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        char infoLog[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        j2d_glGetInfoLogARB(fragmentProgram, 1024, NULL, infoLog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        J2dRlsTraceLn2(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            "OGLContext_CreateFragmentProgram: linker msg (%d):\n%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                       infoLogLength, infoLog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    if (!success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            "OGLContext_CreateFragmentProgram: error linking shader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        j2d_glDeleteObjectARB(fragmentProgram);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    return fragmentProgram;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1031
/*
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1032
 * Class:     sun_java2d_opengl_OGLContext
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1033
 * Method:    getOGLIdString
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1034
 * Signature: ()Ljava/lang/String;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1035
 */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1036
JNIEXPORT jstring JNICALL Java_sun_java2d_opengl_OGLContext_getOGLIdString
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1037
  (JNIEnv *env, jclass oglcc)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1038
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1039
    char *vendor, *renderer, *version;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1040
    char *pAdapterId;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1041
    jobject ret = NULL;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1042
    int len;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1043
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1044
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_getOGLIdString");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1045
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1046
    vendor = (char*)j2d_glGetString(GL_VENDOR);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1047
    if (vendor == NULL) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1048
        vendor = "Unknown Vendor";
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1049
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1050
    renderer = (char*)j2d_glGetString(GL_RENDERER);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1051
    if (renderer == NULL) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1052
        renderer = "Unknown Renderer";
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1053
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1054
    version = (char*)j2d_glGetString(GL_VERSION);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1055
    if (version == NULL) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1056
        version = "unknown version";
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1057
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1058
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1059
    // 'vendor renderer (version)0'
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1060
    len = strlen(vendor) + 1 + strlen(renderer) + 1 + 1+strlen(version)+1 + 1;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1061
    pAdapterId = malloc(len);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1062
    if (pAdapterId != NULL) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1063
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1064
        jio_snprintf(pAdapterId, len, "%s %s (%s)", vendor, renderer, version);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1065
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1066
        J2dTraceLn1(J2D_TRACE_VERBOSE, "  id=%s", pAdapterId);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1067
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1068
        ret = JNU_NewStringPlatform(env, pAdapterId);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1069
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1070
        free(pAdapterId);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1071
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1072
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1073
    return ret;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1074
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
  1075
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
#endif /* !HEADLESS */