alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Android example source code file (GLDebugHelper.java)

This example Android source code file (GLDebugHelper.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Android by Example" TM.

Java - Android tags/keywords

config_check_gl_error, config_check_thread, config_log_argument_names, egl, egllogwrapper, error_wrong_thread, gldebughelper, glerrorwrapper, gllogwrapper, io, writer

The GLDebugHelper.java Android example source code

/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.opengl;

import java.io.Writer;

import javax.microedition.khronos.egl.EGL;
import javax.microedition.khronos.opengles.GL;

/**
 * A helper class for debugging OpenGL ES applications.
 *
 * Wraps the supplied GL interface with a new GL interface that adds support for
 * error checking and logging.
 *
 */
public class GLDebugHelper {

    /**
     * Wrap an existing GL interface in a new GL interface that adds support for
     * error checking and/or logging.
     * <p>
     * Wrapping means that the GL instance that is passed in to this method is
     * wrapped inside a new GL instance that optionally performs additional
     * operations before and after calling the wrapped GL instance.
     * <p>
     * Error checking means that the wrapper will automatically call
     * glError after each GL operation,
     * and throw a GLException if an error occurs. (By design, calling glError
     * itself will not cause an exception to be thrown.) Enabling error checking
     * is an alternative to manually calling glError after every GL operation.
     * <p>
     * Logging means writing a text representation of each GL method call to
     * a log.
     * <p>
     * @param gl the existing GL interface. Must implement GL and GL10. May
     * optionally implement GL11 as well.
     * @param configFlags A bitmask of error checking flags.
     * @param log - null to disable logging, non-null to enable logging.
     * @return the wrapped GL instance.
     */

    /**
     * Check glError() after every call.
     */
    public static final int CONFIG_CHECK_GL_ERROR = (1 << 0);

    /**
     * Check if all calls are on the same thread.
     */
    public static final int CONFIG_CHECK_THREAD = (1 << 1);

    /**
     * Print argument names when logging GL Calls.
     */
    public static final int CONFIG_LOG_ARGUMENT_NAMES = (1 << 2);

    /**
     * The Error number used in the GLException that is thrown if
     * CONFIG_CHECK_THREAD is enabled and you call OpenGL ES on the
     * a different thread.
     */
    public static final int ERROR_WRONG_THREAD = 0x7000;

    public static GL wrap(GL gl, int configFlags, Writer log) {
        if ( configFlags != 0 ) {
            gl = new GLErrorWrapper(gl, configFlags);
        }
        if ( log != null ) {
            boolean logArgumentNames =
                (CONFIG_LOG_ARGUMENT_NAMES & configFlags) != 0;
            gl = new GLLogWrapper(gl, log, logArgumentNames);
        }
        return gl;
    }

    /**
     * Wrap an existing EGL interface in a new EGL interface that adds
     * support for error checking and/or logging.
     * @param egl the existing GL interface. Must implement EGL and EGL10. May
     * optionally implement EGL11 as well.
     * @param configFlags A bitmask of error checking flags.
     * @param log - null to disable logging, non-null to enable logging.
     * @return the wrapped EGL interface.
     */
    public static EGL wrap(EGL egl, int configFlags, Writer log) {
        if (log != null) {
            egl = new EGLLogWrapper(egl, configFlags, log);
        }
        return egl;
    }
}

Other Android examples (source code examples)

Here is a short list of links related to this Android GLDebugHelper.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.