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 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*/); } }
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); } }
@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.texCoordMatrix.set(this.nightTexture.getTexCoordTransform()); this.texCoordMatrix.multiplyByTileTransform(terrain.getSector(), this.fullSphereSector); this.program.loadTexCoordMatrix(this.texCoordMatrix);