⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicwwtexture.java

📁 world wind java sdk 源码
💻 JAVA
字号:
/*Copyright (C) 2001, 2009 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.render;import gov.nasa.worldwind.util.*;import com.sun.opengl.util.texture.*;import javax.media.opengl.*;import java.io.InputStream;import java.awt.image.*;/** * @author tag * @version $Id: BasicWWTexture.java 8767 2009-02-05 11:28:34Z tgaskins $ */public class BasicWWTexture implements WWTexture{    private Object imageSource;    private int width;    private int height;    public BasicWWTexture(Object imageSource)    {        initialize(imageSource);    }    protected void initialize(Object imageSource)    {        // TODO: Throw an exception if image source doesn't exist or cannot be read        // TODO: Make object benign if its image source can't be successfully read        if (imageSource == null)        {            String message = Logging.getMessage("nullValue.ImageSourceIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        this.imageSource = imageSource;    }    public Object getImageSource()    {        return imageSource;    }    public int getWidth()    {        return width;    }    public int getHeight()    {        return height;    }    public boolean isTextureCurrent(DrawContext dc)    {        return true;    }    public boolean bind(DrawContext dc)    {        if (dc == null)        {            String message = Logging.getMessage("nullValue.DrawContextIsNull");            Logging.logger().severe(message);            throw new IllegalStateException(message);        }        Texture t = dc.getTextureCache().get(this.imageSource);        if (t == null)        {            t = this.initializeTexture(dc);            if (t != null)                return true; // texture was bound during initialization.        }        if (t != null)            t.bind();        return t != null;    }    public void applyInternalTransform(DrawContext dc)    {        if (dc == null)        {            String message = Logging.getMessage("nullValue.DrawContextIsNull");            Logging.logger().severe(message);            throw new IllegalStateException(message);        }        // Use the tile's texture if available.        Texture t = dc.getTextureCache().get(this.imageSource);        if (t == null)            t = this.initializeTexture(dc);        if (t != null)        {            if (t.getMustFlipVertically())            {                GL gl = GLContext.getCurrent().getGL();                gl.glMatrixMode(GL.GL_TEXTURE);                gl.glLoadIdentity();                gl.glScaled(1, -1, 1);                gl.glTranslated(0, -1, 0);            }        }    }    protected Texture initializeTexture(DrawContext dc)    {        if (dc == null)        {            String message = Logging.getMessage("nullValue.DrawContextIsNull");            Logging.logger().severe(message);            throw new IllegalStateException(message);        }        Texture t;        if (this.imageSource instanceof String)        {            String path = (String) this.imageSource;            Object streamOrException = WWIO.getFileOrResourceAsStream(path, this.getClass());            if (streamOrException == null || streamOrException instanceof Exception)            {                Logging.logger().log(java.util.logging.Level.SEVERE, "generic.ExceptionAttemptingToReadImageFile",                    streamOrException != null ? streamOrException : path);                return null;            }            try            {                t = TextureIO.newTexture((InputStream) streamOrException, true, null);            }            catch (Exception e)            {                Logging.logger().log(java.util.logging.Level.SEVERE,                    "layers.TextureLayer.ExceptionAttemptingToReadTextureFile", e);                return null;            }        }        else if (this.imageSource instanceof BufferedImage)        {            try            {                t = TextureIO.newTexture((BufferedImage) this.imageSource, true);            }            catch (Exception e)            {                String msg = Logging.getMessage("generic.IOExceptionDuringTextureInitialization");                Logging.logger().log(java.util.logging.Level.SEVERE, msg, e);                return null;            }        }        else        {            Logging.logger().log(java.util.logging.Level.SEVERE, "generic.UnrecognizedImageSourceTypeeType",                this.imageSource.getClass().getName());            return null;        }        if (t == null) // In case JOGL TextureIO returned null        {            Logging.logger().log(java.util.logging.Level.SEVERE, "generic.TextureUnreadable",                this.imageSource instanceof String ? this.imageSource : this.imageSource.getClass().getName());            return null;        }        // Textures with the same path are assumed to be identical textures, so key the texture id off the        // image source.        dc.getTextureCache().put(this.imageSource, t);        t.bind();        GL gl = dc.getGL();        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);//_MIPMAP_LINEAR);        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);        this.width = t.getWidth();        this.height = t.getHeight();        return t;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -