Ejemplo n.º 1
0
/**
 * Disposes all memory and resources allocated for the given OGLContext,
 * which was previously stored in thread-local storage and is about to be
 * destroyed.
 */
static void
WGLGC_DestroyOGLContext(JNIEnv *env, OGLContext *oglc)
{
    J2dTraceLn(J2D_TRACE_INFO, "in WGLGC_DestroyOGLContext");

    if (oglc != NULL) {
        WGLCtxInfo *ctxinfo = (WGLCtxInfo *)oglc->ctxInfo;

        // invalidate the current context
        OGLContext_InvalidateCurrentContext(env);
        j2d_wglMakeCurrent(NULL, NULL);

        if (ctxinfo != NULL) {
            j2d_wglDeleteContext(ctxinfo->context);
            free(ctxinfo);
        }

        if (oglc->xformMatrix != NULL) {
            free(oglc->xformMatrix);
        }

        if (oglc->maskTextureID != 0) {
            j2d_glDeleteTextures(1, &oglc->maskTextureID);
        }

        if (oglc->blitTextureID != 0) {
            j2d_glDeleteTextures(1, &oglc->blitTextureID);
        }

        free(oglc);
    }
}
Ejemplo n.º 2
0
/**
 * Disposes all memory and resources allocated for the given OGLContext,
 * which was previously stored in thread-local storage and is about to be
 * destroyed.
 */
static void
GLXGC_DestroyOGLContext(JNIEnv *env, OGLContext *oglc)
{
    J2dTraceLn(J2D_TRACE_INFO, "in GLXGC_DestroyOGLContext");

    if (oglc != NULL) {
        GLXCtxInfo *ctxinfo = (GLXCtxInfo *)oglc->ctxInfo;

        // invalidate the current context
        OGLContext_InvalidateCurrentContext(env);
        j2d_glXMakeContextCurrent(awt_display, None, None, NULL);

        if (ctxinfo != NULL) {
            j2d_glXDestroyContext(awt_display, ctxinfo->context);
            free(ctxinfo);
        }

        if (oglc->xformMatrix != NULL) {
            free(oglc->xformMatrix);
        }

        if (oglc->maskTextureID != 0) {
            j2d_glDeleteTextures(1, &oglc->maskTextureID);
        }

        if (oglc->blitTextureID != 0) {
            j2d_glDeleteTextures(1, &oglc->blitTextureID);
        }

        free(oglc);
    }
}
Ejemplo n.º 3
0
/**
 * Disposes of all native resources associated with this surface.
 */
void
OGLSD_Flush(JNIEnv *env, OGLSDOps *oglsdo)
{
    J2dTraceLn1(J2D_TRACE_INFO, "OGLSD_Flush: type=%d",
                oglsdo->drawableType);

    if (oglsdo->drawableType == OGLSD_TEXTURE) {
        if (oglsdo->textureID != 0) {
            j2d_glDeleteTextures(1, &oglsdo->textureID);
            oglsdo->textureID = 0;
        }
    } else if (oglsdo->drawableType == OGLSD_FBOBJECT) {
        if (oglsdo->textureID != 0) {
            j2d_glDeleteTextures(1, &oglsdo->textureID);
            oglsdo->textureID = 0;
        }
        if (oglsdo->depthID != 0) {
            j2d_glDeleteRenderbuffersEXT(1, &oglsdo->depthID);
            oglsdo->depthID = 0;
        }
        if (oglsdo->fbobjectID != 0) {
            j2d_glDeleteFramebuffersEXT(1, &oglsdo->fbobjectID);
            oglsdo->fbobjectID = 0;
        }
    } else {
        // dispose windowing system resources (pbuffer, pixmap, etc)
        OGLSD_DestroyOGLSurface(env, oglsdo);
    }
}
Ejemplo n.º 4
0
/**
 * Initializes a framebuffer object, using the given width and height as
 * a guide.  See OGLSD_InitTextureObject() and OGLSD_InitFBObject()
 * for more information.
 */
JNIEXPORT jboolean JNICALL
Java_sun_java2d_opengl_OGLSurfaceData_initFBObject
    (JNIEnv *env, jobject oglsd,
     jlong pData, jboolean isOpaque,
     jboolean texNonPow2, jboolean texRect,
     jint width, jint height)
{
    OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
    GLuint fbobjectID, depthID;

    J2dTraceLn2(J2D_TRACE_INFO,
                "OGLSurfaceData_initFBObject: w=%d h=%d",
                width, height);

    if (oglsdo == NULL) {
        J2dRlsTraceLn(J2D_TRACE_ERROR,
            "OGLSurfaceData_initFBObject: ops are null");
        return JNI_FALSE;
    }

    // initialize color texture object
    if (!OGLSD_InitTextureObject(oglsdo, isOpaque, texNonPow2, texRect,
                                 width, height))
    {
        J2dRlsTraceLn(J2D_TRACE_ERROR,
            "OGLSurfaceData_initFBObject: could not init texture object");
        return JNI_FALSE;
    }

    // initialize framebuffer object using color texture created above
    if (!OGLSD_InitFBObject(&fbobjectID, &depthID,
                            oglsdo->textureID, oglsdo->textureTarget,
                            oglsdo->textureWidth, oglsdo->textureHeight))
    {
        J2dRlsTraceLn(J2D_TRACE_ERROR,
            "OGLSurfaceData_initFBObject: could not init fbobject");
        j2d_glDeleteTextures(1, &oglsdo->textureID);
        return JNI_FALSE;
    }

    oglsdo->drawableType = OGLSD_FBOBJECT;
    // other fields (e.g. width, height) are set in OGLSD_InitTextureObject()
    oglsdo->fbobjectID = fbobjectID;
    oglsdo->depthID = depthID;

    OGLSD_SetNativeDimensions(env, oglsdo,
                              oglsdo->textureWidth, oglsdo->textureHeight);

    // framebuffer objects differ from other OpenGL surfaces in that the
    // value passed to glRead/DrawBuffer() must be GL_COLOR_ATTACHMENTn_EXT,
    // rather than GL_FRONT (or GL_BACK)
    oglsdo->activeBuffer = GL_COLOR_ATTACHMENT0_EXT;

    return JNI_TRUE;
}
Ejemplo n.º 5
0
/**
 * Destroys the OpenGL resources associated with the given OGLContext.
 * It is required that the native context associated with the OGLContext
 * be made current prior to calling this method.
 */
void
OGLContext_DestroyContextResources(OGLContext *oglc)
{
    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_DestroyContextResources");

    if (oglc->xformMatrix != NULL) {
        free(oglc->xformMatrix);
    }

    if (oglc->blitTextureID != 0) {
        j2d_glDeleteTextures(1, &oglc->blitTextureID);
    }
}
Ejemplo n.º 6
0
/**
 * Returns JNI_TRUE only if all of the following conditions are met:
 *   - the GL_EXT_framebuffer_object extension is available
 *   - FBO support has been enabled via the system property
 *   - we can successfully create an FBO with depth capabilities
 */
static jboolean
OGLContext_IsFBObjectExtensionAvailable(JNIEnv *env,
                                        const char *extString)
{
    jboolean isFBObjectEnabled = JNI_FALSE;
    GLuint fbobjectID, textureID, depthID;
    jint width = 1, height = 1;

    J2dTraceLn(J2D_TRACE_INFO, "OGLContext_IsFBObjectExtensionAvailable");

    // first see if the fbobject extension is available
    if (!OGLContext_IsExtensionAvailable(extString,
                                         "GL_EXT_framebuffer_object"))
    {
        return JNI_FALSE;
    }

    // next see if the depth texture extension is available
    if (!OGLContext_IsExtensionAvailable(extString,
                                         "GL_ARB_depth_texture"))
    {
        return JNI_FALSE;
    }

    // next see if the fbobject system property has been enabled
    isFBObjectEnabled =
        JNU_GetStaticFieldByName(env, NULL,
                                 "sun/java2d/opengl/OGLSurfaceData",
                                 "isFBObjectEnabled", "Z").z;
    if (!isFBObjectEnabled) {
        J2dRlsTraceLn(J2D_TRACE_INFO,
                      "OGLContext_IsFBObjectExtensionAvailable: disabled via flag");
        return JNI_FALSE;
    }

    // finally, create a dummy fbobject with depth capabilities to see
    // if this configuration is supported by the drivers/hardware
    // (first we initialize a color texture object that will be used to
    // construct the dummy fbobject)
    j2d_glGenTextures(1, &textureID);
    j2d_glBindTexture(GL_TEXTURE_2D, textureID);
    j2d_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
                     width, height, 0,
                     GL_RGB, GL_UNSIGNED_BYTE, NULL);
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    // initialize framebuffer object using color texture created above
    if (!OGLSD_InitFBObject(&fbobjectID, &depthID,
                            textureID, GL_TEXTURE_2D,
                            width, height))
    {
        J2dRlsTraceLn(J2D_TRACE_INFO,
                      "OGLContext_IsFBObjectExtensionAvailable: fbobject unsupported");
        j2d_glDeleteTextures(1, &textureID);
        return JNI_FALSE;
    }

    // delete the temporary resources
    j2d_glDeleteTextures(1, &textureID);
    j2d_glDeleteRenderbuffersEXT(1, &depthID);
    j2d_glDeleteFramebuffersEXT(1, &fbobjectID);

    J2dRlsTraceLn(J2D_TRACE_INFO,
                  "OGLContext_IsFBObjectExtensionAvailable: fbobject supported");

    return JNI_TRUE;
}