J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | #ifndef OGLContext_h_Included |
| 27 | #define OGLContext_h_Included |
| 28 | |
| 29 | #include "sun_java2d_pipe_BufferedContext.h" |
| 30 | #include "sun_java2d_opengl_OGLContext.h" |
| 31 | |
| 32 | #include "j2d_md.h" |
| 33 | #include "J2D_GL/gl.h" |
| 34 | #include "OGLSurfaceData.h" |
| 35 | |
| 36 | /** |
| 37 | * The OGLBlendRule structure encapsulates the two enumerated values that |
| 38 | * comprise a given Porter-Duff blending (compositing) rule. For example, |
| 39 | * the "SrcOver" rule can be represented by: |
| 40 | * rule.src = GL_ONE; |
| 41 | * rule.dst = GL_ONE_MINUS_SRC_ALPHA; |
| 42 | * |
| 43 | * GLenum src; |
| 44 | * The constant representing the source factor in this Porter-Duff rule. |
| 45 | * |
| 46 | * GLenum dst; |
| 47 | * The constant representing the destination factor in this Porter-Duff rule. |
| 48 | */ |
| 49 | typedef struct { |
| 50 | GLenum src; |
| 51 | GLenum dst; |
| 52 | } OGLBlendRule; |
| 53 | |
| 54 | /** |
| 55 | * The OGLContext structure contains cached state relevant to the native |
| 56 | * OpenGL context stored within the native ctxInfo field. Each Java-level |
| 57 | * OGLContext object is associated with a native-level OGLContext structure. |
| 58 | * The caps field is a bitfield that expresses the capabilities of the |
| 59 | * GraphicsConfig associated with this context (see OGLContext.java for |
| 60 | * the definitions of each capability bit). The other fields are |
| 61 | * simply cached values of various elements of the context state, typically |
| 62 | * used in the OGLContext.set*() methods. |
| 63 | * |
| 64 | * Note that the textureFunction field is implicitly set to zero when the |
| 65 | * OGLContext is created. The acceptable values (e.g. GL_MODULATE, |
| 66 | * GL_REPLACE) for this field are never zero, which means we will always |
| 67 | * validate the texture function state upon the first call to the |
| 68 | * OGLC_UPDATE_TEXTURE_FUNCTION() macro. |
| 69 | */ |
| 70 | typedef struct { |
| 71 | void *ctxInfo; |
| 72 | jint caps; |
| 73 | jint compState; |
| 74 | jfloat extraAlpha; |
| 75 | jint xorPixel; |
| 76 | jint pixel; |
| 77 | jubyte r; |
| 78 | jubyte g; |
| 79 | jubyte b; |
| 80 | jubyte a; |
| 81 | jint paintState; |
| 82 | jboolean useMask; |
| 83 | GLdouble *xformMatrix; |
| 84 | GLuint blitTextureID; |
| 85 | GLint textureFunction; |
| 86 | } OGLContext; |
| 87 | |
| 88 | /** |
| 89 | * See BufferedContext.java for more on these flags... |
| 90 | */ |
| 91 | #define OGLC_NO_CONTEXT_FLAGS \ |
| 92 | sun_java2d_pipe_BufferedContext_NO_CONTEXT_FLAGS |
| 93 | #define OGLC_SRC_IS_OPAQUE \ |
| 94 | sun_java2d_pipe_BufferedContext_SRC_IS_OPAQUE |
| 95 | #define OGLC_USE_MASK \ |
| 96 | sun_java2d_pipe_BufferedContext_USE_MASK |
| 97 | |
| 98 | /** |
| 99 | * Evaluates to true if the given capability bitmask is present for the |
| 100 | * given OGLContext. Note that only the constant name needs to be passed as |
| 101 | * a parameter, as this macro will automatically prepend the full package |
| 102 | * and class name to the constant name. |
| 103 | */ |
| 104 | #define OGLC_IS_CAP_PRESENT(oglc, cap) \ |
| 105 | (((oglc)->caps & (sun_java2d_opengl_OGLContext_##cap)) != 0) |
| 106 | |
| 107 | /** |
| 108 | * At startup we will embed one of the following values in the caps field |
| 109 | * of OGLContext. Later we can use this information to select |
| 110 | * the codepath that offers the best performance for that vendor's |
| 111 | * hardware and/or drivers. |
| 112 | */ |
| 113 | #define OGLC_VENDOR_OTHER 0 |
| 114 | #define OGLC_VENDOR_ATI 1 |
| 115 | #define OGLC_VENDOR_NVIDIA 2 |
| 116 | #define OGLC_VENDOR_SUN 3 |
| 117 | |
| 118 | #define OGLC_VCAP_MASK 0x3 |
| 119 | #define OGLC_VCAP_OFFSET 24 |
| 120 | |
| 121 | #define OGLC_GET_VENDOR(oglc) \ |
| 122 | (((oglc)->caps >> OGLC_VCAP_OFFSET) & OGLC_VCAP_MASK) |
| 123 | |
| 124 | /** |
| 125 | * This constant determines the size of the shared tile texture used |
| 126 | * by a number of image rendering methods. For example, the blit tile texture |
| 127 | * will have dimensions with width OGLC_BLIT_TILE_SIZE and height |
| 128 | * OGLC_BLIT_TILE_SIZE (the tile will always be square). |
| 129 | */ |
| 130 | #define OGLC_BLIT_TILE_SIZE 128 |
| 131 | |
| 132 | /** |
| 133 | * Helper macros that update the current texture function state only when |
| 134 | * it needs to be changed, which helps reduce overhead for small texturing |
| 135 | * operations. The filter state is set on a per-context (not per-texture) |
| 136 | * basis; for example, if we apply one texture using GL_MODULATE followed by |
| 137 | * another texture using GL_MODULATE (under the same context), there is no |
| 138 | * need to set the texture function the second time, as that would be |
| 139 | * redundant. |
| 140 | */ |
| 141 | #define OGLC_INIT_TEXTURE_FUNCTION(oglc, func) \ |
| 142 | do { \ |
| 143 | j2d_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, (func)); \ |
| 144 | (oglc)->textureFunction = (func); \ |
| 145 | } while (0) |
| 146 | |
| 147 | #define OGLC_UPDATE_TEXTURE_FUNCTION(oglc, func) \ |
| 148 | do { \ |
| 149 | if ((oglc)->textureFunction != (func)) { \ |
| 150 | OGLC_INIT_TEXTURE_FUNCTION(oglc, func); \ |
| 151 | } \ |
| 152 | } while (0) |
| 153 | |
| 154 | /** |
| 155 | * Exported methods. |
| 156 | */ |
| 157 | OGLContext *OGLContext_SetSurfaces(JNIEnv *env, jlong pSrc, jlong pDst); |
| 158 | void OGLContext_ResetClip(OGLContext *oglc); |
| 159 | void OGLContext_SetRectClip(OGLContext *oglc, OGLSDOps *dstOps, |
| 160 | jint x1, jint y1, jint x2, jint y2); |
| 161 | void OGLContext_BeginShapeClip(OGLContext *oglc); |
| 162 | void OGLContext_EndShapeClip(OGLContext *oglc, OGLSDOps *dstOps); |
| 163 | void OGLContext_SetExtraAlpha(jfloat ea); |
| 164 | void OGLContext_ResetComposite(OGLContext *oglc); |
| 165 | void OGLContext_SetAlphaComposite(OGLContext *oglc, |
| 166 | jint rule, jfloat extraAlpha, jint flags); |
| 167 | void OGLContext_SetXorComposite(OGLContext *oglc, jint xorPixel); |
| 168 | void OGLContext_ResetTransform(OGLContext *oglc); |
| 169 | void OGLContext_SetTransform(OGLContext *oglc, |
| 170 | jdouble m00, jdouble m10, |
| 171 | jdouble m01, jdouble m11, |
| 172 | jdouble m02, jdouble m12); |
| 173 | |
| 174 | jboolean OGLContext_InitBlitTileTexture(OGLContext *oglc); |
| 175 | GLuint OGLContext_CreateBlitTexture(GLenum internalFormat, GLenum pixelFormat, |
| 176 | GLuint width, GLuint height); |
| 177 | |
| 178 | void OGLContext_DestroyContextResources(OGLContext *oglc); |
| 179 | |
| 180 | jboolean OGLContext_IsExtensionAvailable(const char *extString, char *extName); |
| 181 | void OGLContext_GetExtensionInfo(JNIEnv *env, jint *caps); |
| 182 | jboolean OGLContext_IsVersionSupported(const unsigned char *versionstr); |
| 183 | |
| 184 | GLhandleARB OGLContext_CreateFragmentProgram(const char *fragmentShaderSource); |
| 185 | |
| 186 | #endif /* OGLContext_h_Included */ |