protected SurfaceTextureProgram getShaderProgram(RenderContext rc) { SurfaceTextureProgram program = (SurfaceTextureProgram) rc.getShaderProgram(SurfaceTextureProgram.KEY); if (program == null) { program = (SurfaceTextureProgram) rc.putShaderProgram(SurfaceTextureProgram.KEY, new SurfaceTextureProgram(rc.resources)); } return program; } }
public SurfaceTextureProgram(Resources resources) { try { String vs = WWUtil.readResourceAsText(resources, R.raw.gov_nasa_worldwind_surfacetextureprogram_vert); String fs = WWUtil.readResourceAsText(resources, R.raw.gov_nasa_worldwind_surfacetextureprogram_frag); this.setProgramSources(vs, fs); this.setAttribBindings("vertexPoint", "vertexTexCoord"); } catch (Exception logged) { Logger.logMessage(Logger.ERROR, "SurfaceTextureProgram", "constructor", "errorReadingProgramSource", logged); } }
protected void drawSurfaceTextures(DrawContext dc) { this.program.enablePickMode(dc.pickMode); this.program.enableTexture(true); dc.activeTextureUnit(GLES20.GL_TEXTURE0); this.program.loadModelviewProjection(); this.program.texCoordMatrix[0].multiplyByTileTransform(terrainSector, textureSector); this.program.texCoordMatrix[1].setToTileTransform(terrainSector, textureSector); this.program.loadTexCoordMatrix(); this.program.loadColor(texture.color);
@Override public void draw(DrawContext dc) { if (this.program == null || !this.program.useProgram(dc)) { return; // program unspecified or failed to build } // Accumulate surface textures in the draw context's scratch list. // TODO accumulate in a geospatial quadtree ArrayList<Object> scratchList = dc.scratchList(); try { // Add this surface texture. scratchList.add(this); // Add all surface textures that are contiguous in the drawable queue. Drawable next; while ((next = dc.peekDrawable()) != null && this.canBatchWith(next)) { // check if the drawable at the front of the queue can be batched scratchList.add(dc.pollDrawable()); // take it off the queue } // Draw the accumulated surface textures. this.drawSurfaceTextures(dc); } finally { // Clear the accumulated surface textures. scratchList.clear(); } }
protected void determineActiveProgram(RenderContext rc) { this.activeProgram = (SurfaceTextureProgram) rc.getShaderProgram(SurfaceTextureProgram.KEY); if (this.activeProgram == null) { this.activeProgram = (SurfaceTextureProgram) rc.putShaderProgram(SurfaceTextureProgram.KEY, new SurfaceTextureProgram(rc.resources)); } }