Subversion Repositories AndroidProjects

Rev

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

package com.gebauz.Bauzoid.graphics.texture;

import java.nio.ByteBuffer;

import com.gebauz.Bauzoid.graphics.Graphics;

import android.graphics.Bitmap;
import android.opengl.GLES20;

public class Texture2D extends Texture
{
        private ByteBuffer mPixels = null;
       
        public Texture2D(Graphics graphics)
        {      
                super(graphics);
        }
       
        public void recreate()
        {
                if (mPixels != null)
                {
                        loadTexture(mPixels, width, height);
                }
        }
       
        /** Load texture from a bitmap. */
        public void loadTexture(Bitmap bitmap)
        {
                ByteBuffer buffer = ByteBuffer.allocateDirect(bitmap.getHeight() * bitmap.getWidth() * 4);
        bitmap.copyPixelsToBuffer(buffer);
        buffer.position(0);
       
        loadTexture(buffer, bitmap.getWidth(), bitmap.getHeight());
               
                bitmap.recycle();
        }
       
        /** Load texture from a byte buffer. */
        public void loadTexture(ByteBuffer buffer, int w, int h)
        {
                mPixels = buffer;
               
                width = w;
                height = h;
               
                createTexture();
               
                bind(0);
                //GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
                GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, w, h, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer);        
        }

       
}