[added] TextureData, for loading custom image data for managed textures.
import com.badlogic.gdx.graphics.Pixmap.Format;\r
import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.graphics.TextureData;\r
import com.badlogic.gdx.graphics.glutils.FrameBuffer;\r
import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
import com.badlogic.gdx.math.WindowedMean;\r
TextureWrap vWrap) {\r
return new AndroidTexture(this, (Bitmap)null, minFilter, magFilter, uWrap, vWrap, true, file);\r
}\r
+ \r
+ @Override public Texture newTexture (TextureData textureData, TextureFilter minFilter, TextureFilter magFilter,\r
+ TextureWrap uWrap, TextureWrap vWrap) {\r
+ return new AndroidTexture(this, textureData, minFilter, magFilter, uWrap, vWrap);\r
+ }\r
\r
public void clearManagedCaches () {\r
Mesh.clearAllMeshes();\r
paint.setXfermode(new PorterDuffXfermode(Mode.SRC));\r
}\r
\r
- /**\r
- * {@inheritDoc}\r
- */\r
public AndroidPixmap (Bitmap bitmap) {\r
pixmap = bitmap;\r
\r
import com.badlogic.gdx.graphics.GL10;\r
import com.badlogic.gdx.graphics.Pixmap;\r
import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.TextureData;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
import com.badlogic.gdx.utils.MathUtils;\r
\r
private boolean invalidated = false;\r
/** file handle **/\r
private FileHandle file;\r
+ private TextureData textureData;\r
\r
/**\r
* Creates a new texture based on the given image\r
- * \r
- * @param gl\r
- * @param bitmap\r
*/\r
- AndroidTexture (AndroidGraphics graphics, Bitmap image, TextureFilter minFilter, TextureFilter maxFilter, TextureWrap uWrap,\r
+ AndroidTexture (AndroidGraphics graphics, Bitmap image, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap,\r
TextureWrap vWrap, boolean managed, FileHandle file) {\r
this.file = file;\r
this.isManaged = managed;\r
this.bitmap = image;\r
this.minFilter = minFilter;\r
- this.magFilter = maxFilter;\r
+ this.magFilter = magFilter;\r
this.uWrap = uWrap;\r
this.vWrap = vWrap;\r
+ isMipMap = TextureFilter.isMipMap(minFilter);\r
+\r
if (image != null) {\r
this.texWidth = image.getWidth();\r
this.texHeight = image.getHeight();\r
}\r
\r
- if (TextureFilter.isMipMap(minFilter))\r
- isMipMap = true;\r
- else\r
- isMipMap = false;\r
-\r
createTexture();\r
buildMipmap();\r
Gdx.gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);\r
if (isManaged) textures.add(this);\r
}\r
\r
+ /**\r
+ * Creates a managed texture that loads using the specified TextureData.\r
+ */\r
+ AndroidTexture (AndroidGraphics graphics, TextureData textureData, TextureFilter minFilter, TextureFilter magFilter,\r
+ TextureWrap uWrap, TextureWrap vWrap) {\r
+ this.minFilter = minFilter;\r
+ this.magFilter = magFilter;\r
+ this.uWrap = uWrap;\r
+ this.vWrap = vWrap;\r
+ isMipMap = TextureFilter.isMipMap(minFilter);\r
+\r
+ createTexture();\r
+ textureData.load();\r
+ texWidth = textureData.getWidth();\r
+ texHeight = textureData.getHeight();\r
+\r
+ isManaged = true;\r
+ textures.add(this);\r
+ }\r
+\r
private void rebuild () {\r
createTexture();\r
- buildMipmap();\r
+ if (textureData != null)\r
+ textureData.load();\r
+ else\r
+ buildMipmap();\r
invalidated = false;\r
}\r
\r
* typically they are called before setRenderer so that they take effect immediately.\r
* <p>\r
* <h4>Setting a Renderer</h4>\r
- * Finally, you must call {@link #setRenderer} to register a {@link Renderer}. The renderer is responsible for doing the actual\r
+ * Finally, you must call {@link #setRenderer} to register a Renderer. The renderer is responsible for doing the actual\r
* OpenGL rendering.\r
* <p>\r
* <h3>Rendering Mode</h3>\r
void destroyContext (EGL10 egl, EGLDisplay display, EGLContext context);\r
}\r
\r
- private static class DefaultContextFactory implements EGLContextFactory {\r
+ static class DefaultContextFactory implements EGLContextFactory {\r
\r
public EGLContext createContext (EGL10 egl, EGLDisplay display, EGLConfig config) {\r
return egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, null);\r
void destroySurface (EGL10 egl, EGLDisplay display, EGLSurface surface);\r
}\r
\r
- private static class DefaultWindowSurfaceFactory implements EGLWindowSurfaceFactory {\r
+ static class DefaultWindowSurfaceFactory implements EGLWindowSurfaceFactory {\r
\r
public EGLSurface createWindowSurface (EGL10 egl, EGLDisplay display, EGLConfig config, Object nativeWindow) {\r
return egl.eglCreateWindowSurface(display, config, nativeWindow, null);\r
\r
/**\r
* Initialize EGL for a given configuration spec.\r
- * @param configSpec\r
*/\r
public void start () {\r
/*\r
// Once the thread is started, all accesses to the following member\r
// variables are protected by the sGLThreadManager monitor\r
private boolean mShouldExit;\r
- private boolean mExited;\r
+ boolean mExited;\r
private boolean mPaused;\r
private boolean mHasSurface;\r
private boolean mWaitingForSurface;\r
}\r
}\r
\r
- private static class GLThreadManager {\r
+ static class GLThreadManager {\r
\r
public synchronized void threadExiting (GLThread thread) {\r
if (LOG_THREADS) {\r
private GLThread mEglOwner;\r
}\r
\r
- private static final GLThreadManager sGLThreadManager = new GLThreadManager();\r
- private boolean mSizeChanged = true;\r
+ static final GLThreadManager sGLThreadManager = new GLThreadManager();\r
+ boolean mSizeChanged = true;\r
\r
private GLThread mGLThread;\r
- private EGLConfigChooser mEGLConfigChooser;\r
- private EGLContextFactory mEGLContextFactory;\r
- private EGLWindowSurfaceFactory mEGLWindowSurfaceFactory;\r
- private GLWrapper mGLWrapper;\r
- private int mDebugFlags;\r
+ EGLConfigChooser mEGLConfigChooser;\r
+ EGLContextFactory mEGLContextFactory;\r
+ EGLWindowSurfaceFactory mEGLWindowSurfaceFactory;\r
+ GLWrapper mGLWrapper;\r
+ int mDebugFlags;\r
}\r
}\r
}\r
\r
- private ByteBuffer toByteBuffer (int byteCount, Buffer input) {\r
+ ByteBuffer toByteBuffer (int byteCount, Buffer input) {\r
ByteBuffer result = null;\r
boolean convertWholeBuffer = (byteCount < 0);\r
if (input instanceof ByteBuffer) {\r
* red/green/blue/alpha channels bit depths). Failure to do so would result in an EGL_BAD_MATCH error.
*/
public class GLSurfaceView20 extends GLSurfaceView {
- private static String TAG = "GL2JNIView";
+ static String TAG = "GL2JNIView";
private static final boolean DEBUG = false;
public GLSurfaceView20 (Context context) {
/* Set the renderer responsible for frame rendering */
}
- private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
+ static class ContextFactory implements GLSurfaceView.EGLContextFactory {
private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
public EGLContext createContext (EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
}
}
- private static void checkEglError (String prompt, EGL10 egl) {
+ static void checkEglError (String prompt, EGL10 egl) {
int error;
while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS) {
Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error));
\r
/**\r
* Initialize EGL for a given configuration spec.\r
- * @param configSpec\r
*/\r
public void start () {\r
/*\r
private StringBuilder mBuilder = new StringBuilder();\r
}\r
\r
- private static final Semaphore sEglSemaphore = new Semaphore(1);\r
+ static final Semaphore sEglSemaphore = new Semaphore(1);\r
\r
private GLThread mGLThread;\r
- private EGLConfigChooser mEGLConfigChooser;\r
- private GLWrapper mGLWrapper;\r
+ EGLConfigChooser mEGLConfigChooser;\r
+ GLWrapper mGLWrapper;\r
private int mDebugFlags;\r
private int mRenderMode;\r
private Renderer mRenderer;\r
*/\r
\r
public class JoglAnimator {\r
- private volatile ArrayList/*<GLAutoDrawable>*/ drawables = new ArrayList();\r
+ volatile ArrayList/*<GLAutoDrawable>*/ drawables = new ArrayList();\r
private Runnable runnable;\r
- private Thread thread;\r
- private volatile boolean shouldStop;\r
+ Thread thread;\r
+ volatile boolean shouldStop;\r
protected boolean ignoreExceptions;\r
protected boolean printExceptions;\r
- private boolean runAsFastAsPossible;\r
+ boolean runAsFastAsPossible;\r
\r
// For efficient rendering of Swing components, in particular when\r
// they overlap one another\r
- private List lightweights = new ArrayList();\r
- private Map repaintManagers = new IdentityHashMap();\r
- private Map dirtyRegions = new IdentityHashMap();\r
+ List lightweights = new ArrayList();\r
+ Map repaintManagers = new IdentityHashMap();\r
+ Map dirtyRegions = new IdentityHashMap();\r
\r
/** Creates a new, empty Animator. */\r
public JoglAnimator() {\r
\r
/**\r
* An implemenation of the {@link Application} interface based on Jogl for Windows, Linux and Mac. Instantiate this class with\r
- * apropriate parameters and then register {@link ApplicationListener}, {@link RenderListener} or {@link InputProcessor} instances.\r
+ * apropriate parameters and then register {@link ApplicationListener} or {@link InputProcessor} instances.\r
* \r
* @author mzechner\r
* \r
\r
/**\r
* Creates a new {@link JoglApplication} with the given title and dimensions. If useGL20IfAvailable is set the JoglApplication\r
- * will try to create an OpenGL 2.0 context which can then be used via {@link JoglApplication.getGraphics().getGL20()}. To query whether enabling OpenGL 2.0\r
- * was successful use the {@link JoglApplication.getGraphics().isGL20Available()} method.\r
+ * will try to create an OpenGL 2.0 context which can then be used via JoglApplication.getGraphics().getGL20(). To query whether enabling OpenGL 2.0\r
+ * was successful use the JoglApplication.getGraphics().isGL20Available() method.\r
* \r
* @param listener the ApplicationListener implementing the program logic\r
* @param title the title of the application\r
}\r
}\r
\r
- private void initialize(ApplicationListener listener, String title, int width, int height, boolean useGL20) {\r
+ void initialize(ApplicationListener listener, String title, int width, int height, boolean useGL20) {\r
JoglNativesLoader.loadLibraries();\r
graphics = new JoglGraphics(listener, title, width, height, useGL20);\r
input = new JoglInput(graphics.getCanvas());\r
import com.badlogic.gdx.graphics.GLCommon;\r
import com.badlogic.gdx.graphics.Pixmap;\r
import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.TextureData;\r
import com.badlogic.gdx.graphics.Pixmap.Format;\r
import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
return new JoglTexture((BufferedImage) pixmap.getNativePixmap(),\r
minFilter, magFilter, uWrap, vWrap, false);\r
}\r
+\r
+ @Override\r
+ public Texture newTexture (TextureData textureData, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap,\r
+ TextureWrap vWrap) {\r
+ return new JoglTexture(textureData, minFilter, magFilter, uWrap, vWrap);\r
+ }\r
}\r
\r
import java.awt.image.BufferedImage;\r
import java.io.InputStream;\r
+import java.nio.ByteBuffer;\r
+import java.nio.ByteOrder;\r
+import java.nio.IntBuffer;\r
\r
import javax.imageio.ImageIO;\r
import javax.media.opengl.GL;\r
import javax.media.opengl.GLContext;\r
\r
+import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.graphics.Pixmap;\r
import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
+import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
import com.sun.opengl.util.texture.TextureData;\r
import com.sun.opengl.util.texture.TextureIO;\r
\r
/**\r
* Create a new texture\r
- * \r
- * @param textureID The GL texture ID\r
*/\r
- JoglTexture (InputStream in, TextureFilter minFilter, TextureFilter maxFilter, TextureWrap uWrap, TextureWrap vWrap,\r
+ JoglTexture (InputStream in, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap,\r
boolean managed) {\r
this.isManaged = managed;\r
try {\r
\r
bind();\r
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, getTextureFilter(maxFilter));\r
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, getTextureFilter(magFilter));\r
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
this.texWidth = texture.getWidth();\r
textures++;\r
}\r
\r
- JoglTexture (BufferedImage image, TextureFilter minFilter, TextureFilter maxFilter, TextureWrap uWrap, TextureWrap vWrap,\r
+ JoglTexture (BufferedImage image, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap,\r
boolean managed) {\r
this.isManaged = managed;\r
texture = com.sun.opengl.util.texture.TextureIO.newTexture(image, TextureFilter.isMipMap(minFilter) ? true : false);\r
\r
bind();\r
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, getTextureFilter(maxFilter));\r
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, getTextureFilter(magFilter));\r
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
this.texWidth = texture.getWidth();\r
\r
/**\r
* Create a new texture\r
- * \r
- * @param textureID The GL texture ID\r
*/\r
- JoglTexture (int width, int height, int format, TextureFilter minFilter, TextureFilter maxFilter, TextureWrap uWrap,\r
+ JoglTexture (int width, int height, int format, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap,\r
TextureWrap vWrap, boolean managed) {\r
this.isManaged = managed;\r
BufferedImage image = new BufferedImage(width, height, format);\r
\r
bind();\r
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, getTextureFilter(maxFilter));\r
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, getTextureFilter(magFilter));\r
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
this.texWidth = texture.getWidth();\r
textures++;\r
}\r
\r
+ public JoglTexture (com.badlogic.gdx.graphics.TextureData textureData, TextureFilter minFilter, TextureFilter magFilter,\r
+ TextureWrap uWrap, TextureWrap vWrap) {\r
+ this.isManaged = false;\r
+ GL gl = GLContext.getCurrent().getGL();\r
+ \r
+ ByteBuffer buffer = ByteBuffer.allocateDirect(4);\r
+ buffer.order(ByteOrder.nativeOrder());\r
+ IntBuffer intBuffer = buffer.asIntBuffer();\r
+ gl.glGenTextures(1, intBuffer);\r
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(intBuffer.get(0));\r
+\r
+ bind();\r
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, getTextureFilter(magFilter));\r
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
+\r
+ textureData.load();\r
+ texWidth = textureData.getWidth();\r
+ texHeight = textureData.getHeight();\r
+\r
+ textures++;\r
+ }\r
+\r
private int getTextureFilter (TextureFilter filter) {\r
if (filter == TextureFilter.Linear)\r
return GL.GL_LINEAR;\r
import com.badlogic.gdx.graphics.Pixmap.Format;\r
import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.graphics.TextureData;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
import com.badlogic.gdx.utils.MathUtils;\r
\r
return new LwjglTexture(file, minFilter, magFilter, uWrap, vWrap, false);\r
}\r
\r
+ public Texture newTexture (TextureData textureData, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap,\r
+ TextureWrap vWrap) {\r
+ return new LwjglTexture(textureData, minFilter, magFilter, uWrap, vWrap);\r
+ }\r
+\r
public float getDeltaTime () {\r
return deltaTime;\r
}\r
import java.nio.IntBuffer;\r
\r
import org.lwjgl.BufferUtils;\r
-import org.lwjgl.opengl.GL11;\r
-import org.lwjgl.opengl.GL12;\r
+import static org.lwjgl.opengl.GL11.*;\r
+import static org.lwjgl.opengl.GL12.*;\r
\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.backends.lwjgl.PNGDecoder.Format;\r
import com.badlogic.gdx.files.FileHandle;\r
import com.badlogic.gdx.graphics.Pixmap;\r
import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
+import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.graphics.TextureData;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
/**\r
- * I apologize for this class. It is a big fucking mess which can be attributed to the late hour i created this piece of shit in.\r
- * Please take my apologize. It is slow. It is ugly. It is aids.\r
- * \r
* @author badlogicgames@gmail.com\r
- * \r
+ * @author Nathan Sweet <misc@n4te.com>\r
*/\r
final class LwjglTexture implements Texture {\r
/** height in pixels of texture **/\r
static private IntBuffer intBuffer;\r
static private final PNGDecoder pngDecoder = new PNGDecoder();\r
\r
- /**\r
- * Create a new texture\r
- */\r
LwjglTexture (FileHandle file, TextureFilter minFilter, TextureFilter maxFilter, TextureWrap uWrap, TextureWrap vWrap,\r
boolean managed) {\r
this.isManaged = managed;\r
this.isMipMapped = TextureFilter.isMipMap(minFilter);\r
- if (file.getPath().endsWith(".png"))\r
+\r
+ if (!isMipMapped && file.getPath().endsWith(".png")) {\r
+ // Fast path.\r
loadPNG(file);\r
- else {\r
+ } else {\r
BufferedImage image = (BufferedImage)Gdx.graphics.newPixmap(file).getNativePixmap();\r
loadMipMap(image);\r
}\r
bind();\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, getTextureFilter(maxFilter));\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, getTextureFilter(maxFilter));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
textures++;\r
}\r
\r
boolean managed) {\r
this.isManaged = managed;\r
this.isMipMapped = TextureFilter.isMipMap(minFilter);\r
+\r
BufferedImage img = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);\r
loadMipMap(img);\r
this.draw(Gdx.graphics.newPixmap(image), 0, 0);\r
bind();\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, getTextureFilter(maxFilter));\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, getTextureFilter(maxFilter));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
textures++;\r
}\r
\r
- /**\r
- * Create a new texture\r
- */\r
LwjglTexture (int width, int height, int format, TextureFilter minFilter, TextureFilter maxFilter, TextureWrap uWrap,\r
TextureWrap vWrap, boolean managed) {\r
this.isManaged = managed;\r
this.isMipMapped = TextureFilter.isMipMap(minFilter);\r
+\r
BufferedImage image = new BufferedImage(width, height, format);\r
loadMipMap(image);\r
bind();\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, getTextureFilter(maxFilter));\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, getTextureFilter(maxFilter));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
+ textures++;\r
+ }\r
+\r
+ public LwjglTexture (TextureData textureData, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap,\r
+ TextureWrap vWrap) {\r
+ isManaged = false;\r
+ this.isMipMapped = TextureFilter.isMipMap(minFilter);\r
+\r
+ textureID = glGenTextures();\r
+ bind();\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, getTextureFilter(magFilter));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, getTextureWrap(uWrap));\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, getTextureWrap(vWrap));\r
+\r
+ textureData.load();\r
+ texWidth = textureData.getWidth();\r
+ texHeight = textureData.getHeight();\r
+\r
textures++;\r
}\r
\r
int glFormat, glInternalFormat;\r
switch (pngFormat) {\r
case ALPHA:\r
- glFormat = GL11.GL_ALPHA;\r
- glInternalFormat = GL11.GL_ALPHA8;\r
+ glFormat = GL_ALPHA;\r
+ glInternalFormat = GL_ALPHA8;\r
break;\r
case LUMINANCE:\r
- glFormat = GL11.GL_LUMINANCE;\r
- glInternalFormat = GL11.GL_LUMINANCE8;\r
+ glFormat = GL_LUMINANCE;\r
+ glInternalFormat = GL_LUMINANCE8;\r
break;\r
case LUMINANCE_ALPHA:\r
- glFormat = GL11.GL_LUMINANCE_ALPHA;\r
- glInternalFormat = GL11.GL_LUMINANCE8_ALPHA8;\r
+ glFormat = GL_LUMINANCE_ALPHA;\r
+ glInternalFormat = GL_LUMINANCE8_ALPHA8;\r
break;\r
case RGB:\r
- glFormat = GL11.GL_RGB;\r
- glInternalFormat = GL11.GL_RGB8;\r
+ glFormat = GL_RGB;\r
+ glInternalFormat = GL_RGB8;\r
break;\r
case RGBA:\r
- glFormat = GL11.GL_RGBA;\r
- glInternalFormat = GL11.GL_RGBA8;\r
+ glFormat = GL_RGBA;\r
+ glInternalFormat = GL_RGBA8;\r
break;\r
case BGRA:\r
- glFormat = GL12.GL_BGRA;\r
- glInternalFormat = GL12.GL_BGRA;\r
+ glFormat = GL_BGRA;\r
+ glInternalFormat = GL_BGRA;\r
break;\r
default:\r
throw new UnsupportedOperationException("PNG format not handled: " + pngFormat);\r
pngDecoder.decode(buffer, stride, pngFormat);\r
buffer.flip();\r
\r
- textureID = GL11.glGenTextures();\r
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);\r
- GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, glInternalFormat, texWidth, texHeight, 0, glFormat, GL11.GL_UNSIGNED_BYTE,\r
- buffer);\r
- // FIXME - No mipmapping!\r
+ textureID = glGenTextures();\r
+ glBindTexture(GL_TEXTURE_2D, textureID);\r
+ glTexImage2D(GL_TEXTURE_2D, 0, glInternalFormat, texWidth, texHeight, 0, glFormat, GL_UNSIGNED_BYTE, buffer);\r
} catch (IOException ex) {\r
throw new GdxRuntimeException("Error loading image file: " + file, ex);\r
}\r
int width = image.getWidth();\r
texWidth = width;\r
texHeight = height;\r
- textureID = GL11.glGenTextures();\r
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);\r
+ textureID = glGenTextures();\r
+ glBindTexture(GL_TEXTURE_2D, textureID);\r
\r
while (height >= 1 || width >= 1 && level < 4) {\r
ByteBuffer imageBuffer = toByteBuffer(image);\r
- GL11.glTexImage2D(GL11.GL_TEXTURE_2D, level, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE,\r
- imageBuffer);\r
- if (height == 1 || width == 1 || isMipMapped == false) {\r
- break;\r
- }\r
+ glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, imageBuffer);\r
+ if (height == 1 || width == 1 || isMipMapped == false) break;\r
\r
level++;\r
if (height > 1) height /= 2;\r
\r
private int getTextureFilter (TextureFilter filter) {\r
if (filter == TextureFilter.Linear)\r
- return GL11.GL_LINEAR;\r
+ return GL_LINEAR;\r
else if (filter == TextureFilter.Nearest)\r
- return GL11.GL_NEAREST;\r
+ return GL_NEAREST;\r
else if (filter == TextureFilter.MipMap)\r
- return GL11.GL_LINEAR_MIPMAP_LINEAR;\r
+ return GL_LINEAR_MIPMAP_LINEAR;\r
else if (filter == TextureFilter.MipMapNearestNearest)\r
- return GL11.GL_NEAREST_MIPMAP_NEAREST;\r
+ return GL_NEAREST_MIPMAP_NEAREST;\r
else if (filter == TextureFilter.MipMapNearestLinear)\r
- return GL11.GL_NEAREST_MIPMAP_LINEAR;\r
+ return GL_NEAREST_MIPMAP_LINEAR;\r
else if (filter == TextureFilter.MipMapLinearNearest)\r
- return GL11.GL_LINEAR_MIPMAP_NEAREST;\r
+ return GL_LINEAR_MIPMAP_NEAREST;\r
else if (filter == TextureFilter.MipMapLinearLinear)\r
- return GL11.GL_LINEAR_MIPMAP_LINEAR;\r
+ return GL_LINEAR_MIPMAP_LINEAR;\r
else\r
- return GL11.GL_LINEAR_MIPMAP_LINEAR;\r
+ return GL_LINEAR_MIPMAP_LINEAR;\r
}\r
\r
private int getTextureWrap (TextureWrap wrap) {\r
if (wrap == TextureWrap.ClampToEdge)\r
- return GL11.GL_CLAMP;\r
+ return GL_CLAMP;\r
else\r
- return GL11.GL_REPEAT;\r
+ return GL_REPEAT;\r
}\r
\r
public boolean isManaged () {\r
}\r
\r
public void bind () {\r
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);\r
+ glBindTexture(GL_TEXTURE_2D, textureID);\r
}\r
\r
public void dispose () {\r
- GL11.glDeleteTextures(textureID);\r
+ glDeleteTextures(textureID);\r
textures--;\r
}\r
\r
bind();\r
while (height >= 1 || width >= 1 && level < 4) {\r
ByteBuffer imageBuffer = toByteBuffer(image);\r
- GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, level, x, y, width, height, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, imageBuffer);\r
- if (height == 1 || width == 1 || isMipMapped == false) {\r
- break;\r
- }\r
+ glTexSubImage2D(GL_TEXTURE_2D, level, x, y, width, height, GL_BGRA, GL_UNSIGNED_BYTE, imageBuffer);\r
+ if (height == 1 || width == 1 || isMipMapped == false) break;\r
\r
level++;\r
if (height > 1) height /= 2;\r
import com.badlogic.gdx.graphics.GLCommon;\r
import com.badlogic.gdx.graphics.Mesh;\r
import com.badlogic.gdx.graphics.Pixmap;\r
+import com.badlogic.gdx.graphics.TextureData;\r
import com.badlogic.gdx.graphics.Pixmap.Format;\r
import com.badlogic.gdx.graphics.SpriteBatch;\r
import com.badlogic.gdx.graphics.Texture;\r
Texture.TextureWrap vWrap);\r
\r
/**\r
+ * Creates a new {@link Texture} that loads its data from the given {@link TextureData}. The texture is managed and the\r
+ * TextureData may be asked to load the image data multiple times throughout the application's lifetime. If the minification\r
+ * filter is specified as {@link Texture.TextureFilter#MipMap}, mipmaps will not be created automatically and must be handled\r
+ * by the TextureData. The Texture must be disposed via the {@link Texture#dispose()} methods once it is no longer used.\r
+ * Textures created via this method are managed and will be recreated automatically after the OpenGL context has been lost and\r
+ * recreated.\r
+ * @param textureData Loads the texture data into GL.\r
+ * @throws GdxRuntimeException if the texture could not be created.\r
+ */\r
+ public Texture newTexture (TextureData textureData, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap,\r
+ TextureWrap vWrap);\r
+\r
+ /**\r
* @return the {@link GraphicsType} of this Graphics instance\r
*/\r
- public GraphicsType getType();\r
+ public GraphicsType getType ();\r
}\r
--- /dev/null
+\r
+package com.badlogic.gdx.graphics;\r
+\r
+import com.badlogic.gdx.Graphics;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
+import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+\r
+/**\r
+ * Loads image data for a texture. Used with\r
+ * {@link Graphics#newTexture(TextureData, TextureFilter, TextureFilter, TextureWrap, TextureWrap) newTexture}, this allows custom\r
+ * image loading for managed textures. If the OpenGL context is lost, the TextureData will be asked to load again when the context\r
+ * is restored. The TextureData doesn't necessary need to keep the image data in memory between loads.\r
+ */\r
+public interface TextureData {\r
+ /**\r
+ * Loads the image data into the currently bound texture. Usually\r
+ * {@link GL10#glTexImage2D(int, int, int, int, int, int, int, int, java.nio.Buffer)} is used.\r
+ */\r
+ public void load ();\r
+\r
+ /**\r
+ * Returns the width of the texture, which must be a power of two. This will not be called before {@link #load()}.\r
+ */\r
+ public int getWidth ();\r
+\r
+ /**\r
+ * Returns the height of the texture, which must be a power of two. This will not be called before {@link #load()}.\r
+ */\r
+ public int getHeight ();\r
+}\r
private ArrayList<Body> boxes = new ArrayList<Body>();\r
\r
/** our ground box **/\r
- private Body groundBody;\r
+ Body groundBody;\r
\r
/** our mouse joint **/\r
private MouseJoint mouseJoint = null;\r
\r
/** a hit body **/\r
- private Body hitBody = null;\r
+ Body hitBody = null;\r
\r
@Override public void create () {\r
// setup the camera. In Box2D we operate on a\r
return sum;\r
}\r
\r
- @SuppressWarnings("unused") private static float sum (FloatBuffer buffer) {\r
+ private static float sum (FloatBuffer buffer) {\r
float sum = 0;\r
for (int i = 1; i < SAMPLES / 2 + 1; i++)\r
sum += buffer.get(i) * 2 / SAMPLES;\r
return sum;\r
}\r
\r
- @SuppressWarnings("unused") private static void createFlat (float samples[], ShortBuffer shortSamples) {\r
+ private static void createFlat (float samples[], ShortBuffer shortSamples) {\r
for (int i = 0; i < samples.length; i++) {\r
samples[i] = 1;\r
shortSamples.put(Short.MAX_VALUE);\r
private String score = "";\r
\r
/**\r
- * Here we setup all the resources. A {@link MeshRenderer} for the paddles which we use for both, a MeshRenderer for the ball\r
- * and a {@link Text} for rendering the score.\r
+ * Here we setup all the resources. A MeshRenderer for the paddles which we use for both, a MeshRenderer for the ball\r
+ * and a Text for rendering the score.\r
*/\r
@Override public void create () {\r
setupGraphics();\r
\r
/**\r
* This method sets up all the graphics related stuff like the Meshes, the camera and the Font\r
- * @param app\r
*/\r
private void setupGraphics () {\r
//\r
\r
/**\r
* Updates the game state, moves the ball, checks for collisions or whether the ball has left the playfield.\r
- * \r
- * @param deltaTime the time elapsed since the last frame\r
*/\r
private void updateGame () {\r
// the delta time so we can do frame independant time based movement\r
public float height;\r
public float width;\r
\r
- private SimpleRect (int index, float x, float y, float width, float height) {\r
+ SimpleRect (int index, float x, float y, float width, float height) {\r
this.index = index;\r
this.x = x;\r
this.y = y;\r
private final static short k_smallGroup = 1;\r
private final static short k_largeGroup = -1;\r
\r
- @SuppressWarnings("unused") private final static short k_defaultCategory = 0x0001;\r
+ private final static short k_defaultCategory = 0x0001;\r
private final static short k_triangleCategory = 0x0002;\r
private final static short k_boxCategory = 0x0004;\r
private final static short k_circleCategory = 0x0008;\r