Subversion Repositories AndroidProjects

Rev

Rev 186 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.Bauzoid.graphics;

import javax.microedition.khronos.opengles.GL;
import javax.microedition.khronos.opengles.GL10;

import com.gebauz.Bauzoid.app.Consts;
import com.gebauz.Bauzoid.graphics.renderstate.RenderStates;

import android.util.Log;

public class GLUtil
{
        private static GLUtil mInstance = new GLUtil();
       
        private GL10 mGLContext = null;
        private int mWidth;
        private int mHeight;
       
        private RenderStates mRenderStates = new RenderStates();
       
        private GLUtil()
        {
        }
       
        public static GLUtil getInstance()
        {
                return mInstance;                      
        }
       
        public static void setGL(GL10 newContext)
        {
                mInstance.mGLContext = newContext;
                //mInstance.mRenderStates.initialize();
        }
       
        public static GL10 getGL()
        {
                return mInstance.mGLContext;
        }
       
        public static RenderStates getRenderStates()
        {
                return mInstance.mRenderStates;
        }
       
        public static void checkError(GL gl)
        {
        int error = getGL().glGetError();
        if (error != GL10.GL_NO_ERROR)
        {
                Log.v(Consts.LOG_TAG, "GLError 0x" + Integer.toHexString(error));
            throw new RuntimeException("GLError 0x" + Integer.toHexString(error));
        }
    }
       
    public static boolean checkFboSupport()
    {
        return checkExtension("GL_OES_framebuffer_object");
    }

    /**
     * This is not the fastest way to check for an extension, but fine if
     * we are only checking for a few extensions each time a context is created.
     * @param gl
     * @param extension
     * @return true if the extension is present in the current context.
     */

    public static boolean checkExtension(String extension)
    {
        GL10 gl = getGL();
        String extensions = " " + gl.glGetString(GL10.GL_EXTENSIONS) + " ";
        // The extensions string is padded with spaces between extensions, but not
        // necessarily at the beginning or end. For simplicity, add spaces at the
        // beginning and end of the extensions string and the extension string.
        // This means we can avoid special-case checks for the first or last
        // extension, as well as avoid special-case checks when an extension name
        // is the same as the first part of another extension name.
        return extensions.indexOf(" " + extension + " ") >= 0;
    }
       
        public final int getWidth() { return mWidth; }
        public final void setWidth(int w) { mWidth = w; }
       
        public final int getHeight() { return mHeight; }
        public final void setHeight(int h) { mHeight = h; }

}