@Override public boolean bindTexture(DrawContext dc) { return (this.texture != null) && this.texture.bindTexture(dc); }
protected Matrix3 computeRepeatingTexCoordTransform(Texture texture, double metersPerPixel, Matrix3 result) { Matrix3 texCoordMatrix = result.setToIdentity(); texCoordMatrix.setScale( 1.0 / (texture.getWidth() * metersPerPixel), 1.0 / (texture.getHeight() * metersPerPixel)); texCoordMatrix.multiplyByMatrix(texture.getTexCoordTransform()); return texCoordMatrix; }
protected Texture createTexture(ImageSource imageSource, ImageOptions options, Bitmap bitmap) { Texture texture = new Texture(bitmap); if (options != null && options.resamplingMode == WorldWind.NEAREST_NEIGHBOR) { texture.setTexParameter(GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); texture.setTexParameter(GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); } if (options != null && options.wrapMode == WorldWind.REPEAT) { texture.setTexParameter(GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); texture.setTexParameter(GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); } return texture; }
public boolean bindTexture(DrawContext dc) { if (this.textureName == UNINITIALIZED_NAME) { this.createTexture(dc); } if (this.textureName[0] != 0) { dc.bindTexture(this.textureName[0]); } if (this.textureName[0] != 0 && this.pickMode != dc.pickMode) { this.setTexParameters(dc); this.pickMode = dc.pickMode; } return this.textureName[0] != 0; }
protected void doDraw(DrawContext dc, DrawableScreenTexture drawable) { // Use the drawable's color. drawable.program.loadColor(drawable.color); // Attempt to bind the drawable's texture, configuring the shader program appropriately if there is no texture // or if the texture failed to bind. if (drawable.texture != null && drawable.texture.bindTexture(dc)) { drawable.program.enableTexture(true); drawable.program.loadTexCoordMatrix(drawable.texture.getTexCoordTransform()); } else { drawable.program.enableTexture(false); } // Use a modelview-projection matrix that transforms the unit square to screen coordinates. drawable.mvpMatrix.setToMultiply(dc.screenProjection, drawable.unitSquareTransform); drawable.program.loadModelviewProjection(drawable.mvpMatrix); // Disable depth testing if requested. if (!drawable.enableDepthTest) { GLES20.glDisable(GLES20.GL_DEPTH_TEST); } // Draw the unit square as triangles. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); // Restore the default WorldWind OpenGL state. if (!drawable.enableDepthTest) { GLES20.glEnable(GLES20.GL_DEPTH_TEST); } }
GLES20.glViewport(0, 0, colorAttachment.getWidth(), colorAttachment.getHeight()); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glDisable(GLES20.GL_DEPTH_TEST); this.drawState.program.loadColor(prim.color); if (prim.texture != null && prim.texture.bindTexture(dc)) { this.drawState.program.loadTexCoordMatrix(prim.texCoordMatrix); this.drawState.program.enableTexture(true);
protected void createTexture(DrawContext dc) { int currentTexture = dc.currentTexture(); try { // Create the OpenGL texture 2D object. this.textureName = new int[1]; GLES20.glGenTextures(1, this.textureName, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, this.textureName[0]); // Specify the texture object's image data, either by loading a bitmap or by allocating an empty image. if (this.imageBitmap != null) { this.loadTexImage(dc, this.imageBitmap); this.imageBitmap = null; } else { this.allocTexImage(dc); } // Configure the texture object's parameters. this.setTexParameters(dc); } finally { // Restore the current OpenGL texture object binding. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, currentTexture); } }
protected void addTile(RenderContext rc, ImageTile tile) { ImageSource imageSource = tile.getImageSource(); if (imageSource == null) { return; // no image source indicates an empty level or an image missing from the tiled data store } Texture texture = rc.getTexture(imageSource); // try to get the texture from the cache if (texture == null) { texture = rc.retrieveTexture(imageSource, this.imageOptions); // puts retrieved textures in the cache } if (texture != null) { // use the tile's own texture Pool<DrawableSurfaceTexture> pool = rc.getDrawablePool(DrawableSurfaceTexture.class); Drawable drawable = DrawableSurfaceTexture.obtain(pool).set(this.activeProgram, tile.sector, texture, texture.getTexCoordTransform()); rc.offerSurfaceDrawable(drawable, 0 /*z-order*/); } else if (this.ancestorTile != null) { // use the ancestor tile's texture, transformed to fill the tile sector this.ancestorTexCoordMatrix.set(this.ancestorTexture.getTexCoordTransform()); this.ancestorTexCoordMatrix.multiplyByTileTransform(tile.sector, this.ancestorTile.sector); Pool<DrawableSurfaceTexture> pool = rc.getDrawablePool(DrawableSurfaceTexture.class); Drawable drawable = DrawableSurfaceTexture.obtain(pool).set(this.activeProgram, tile.sector, this.ancestorTexture, this.ancestorTexCoordMatrix); rc.offerSurfaceDrawable(drawable, 0 /*z-order*/); } }
public Texture putTexture(ImageSource imageSource, Texture texture) { this.renderResourceCache.put(imageSource, texture, (texture != null) ? texture.getByteCount() : 0); return texture; }
public Texture(int width, int height, int format, int type) { if (width < 0 || height < 0) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Texture", "constructor", "invalidWidthOrHeight")); } this.textureWidth = width; this.textureHeight = height; this.textureFormat = format; this.textureType = type; this.textureByteCount = estimateByteCount(width, height, format, type); this.texCoordTransform.setToIdentity(); }
@Override public void release(DrawContext dc) { if (this.textureName[0] != 0) { this.deleteTexture(dc); } if (this.imageBitmap != null) { this.imageBitmap = null; // imageBitmap can be non-null if the texture has never been used } }
public int getTextureName(DrawContext dc) { if (this.textureName == UNINITIALIZED_NAME) { this.createTexture(dc); } return this.textureName[0]; }
public Texture renderText(String text) { if (text != null && text.length() > 0) { Bitmap bitmap = this.drawText(text); return new Texture(bitmap); } else { return null; } }
} else if ((param = this.getTexParameter(GLES20.GL_TEXTURE_MIN_FILTER)) != 0) { GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, param); } else { } else if ((param = this.getTexParameter(GLES20.GL_TEXTURE_MAG_FILTER)) != 0) { GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, param); } else { if ((param = this.getTexParameter(GLES20.GL_TEXTURE_WRAP_S)) != 0) { GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, param); } else { if ((param = this.getTexParameter(GLES20.GL_TEXTURE_WRAP_T)) != 0) { GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, param); } else {
boolean textureBound = this.nightTexture != null && this.nightTexture.bindTexture(dc); this.texCoordMatrix.set(this.nightTexture.getTexCoordTransform()); this.texCoordMatrix.multiplyByTileTransform(terrain.getSector(), this.fullSphereSector); this.program.loadTexCoordMatrix(this.texCoordMatrix);
@Override protected void doRender(RenderContext rc) { if (this.sector.isEmpty()) { return; // nothing to render } if (!rc.terrain.getSector().intersects(this.sector)) { return; // no terrain surface to render on } Texture texture = rc.getTexture(this.imageSource); // try to get the texture from the cache if (texture == null) { texture = rc.retrieveTexture(this.imageSource, this.imageOptions); // puts retrieved textures in the cache } if (texture == null) { return; // no texture to draw } // Enqueue a drawable surface texture for processing on the OpenGL thread. SurfaceTextureProgram program = this.getShaderProgram(rc); Pool<DrawableSurfaceTexture> pool = rc.getDrawablePool(DrawableSurfaceTexture.class); DrawableSurfaceTexture drawable = DrawableSurfaceTexture.obtain(pool).set(program, this.sector, texture, texture.getTexCoordTransform()); rc.offerSurfaceDrawable(drawable, 0 /*z-order*/); // Enqueue a picked object that associates the drawable surface texture with this surface image. if (rc.pickMode) { int pickedObjectId = rc.nextPickedObjectId(); PickedObject.identifierToUniqueColor(pickedObjectId, drawable.color); rc.offerPickedObject(PickedObject.fromRenderable(pickedObjectId, this, rc.currentLayer)); } }
this.put(imageSource, texture, texture.getByteCount()); return texture; if (bitmap != null) { Texture texture = this.createTexture(imageSource, options, bitmap); this.put(imageSource, texture, texture.getByteCount()); return texture;
public Texture(Bitmap bitmap) { if (bitmap == null || bitmap.isRecycled()) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Texture", "constructor", (bitmap == null) ? "missingBitmap" : "invalidBitmap")); } int width = bitmap.getWidth(); int height = bitmap.getHeight(); int format = GLUtils.getInternalFormat(bitmap); int type = GLUtils.getType(bitmap); this.textureWidth = width; this.textureHeight = height; this.textureFormat = format; this.textureType = type; this.textureByteCount = estimateByteCount(width, height, format, type); this.texCoordTransform.setToVerticalFlip(); this.imageBitmap = bitmap; }