this.drawState.program.enablePickMode(false); this.drawState.program.enableTexture(true); this.drawState.program.loadTexCoordMatrix(this.identityMatrix3); this.drawState.program.loadColor(this.color); this.mvpMatrix.set(dc.modelviewProjection); this.mvpMatrix.multiplyByTranslation(terrainOrigin.x, terrainOrigin.y, terrainOrigin.z); this.drawState.program.loadModelviewProjection(this.mvpMatrix);
public BasicShaderProgram(Resources resources) { try { String vs = WWUtil.readResourceAsText(resources, R.raw.gov_nasa_worldwind_basicprogram_vert); String fs = WWUtil.readResourceAsText(resources, R.raw.gov_nasa_worldwind_basicprogram_frag); this.setProgramSources(vs, fs); this.setAttribBindings("vertexPoint", "vertexTexCoord"); } catch (Exception logged) { Logger.logMessage(Logger.ERROR, "BasicShaderProgram", "constructor", "errorReadingProgramSource", logged); } }
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); } }
/** * Prepares this placemark's icon or symbol for processing in a subsequent drawing pass. Implementations must be * careful not to leak resources from Placemark into the Drawable. * * @param rc the current render context * @param drawable the Drawable to be prepared */ protected void prepareDrawableIcon(RenderContext rc, DrawableScreenTexture drawable) { // Use the basic GLSL program to draw the placemark's icon. drawable.program = (BasicShaderProgram) rc.getShaderProgram(BasicShaderProgram.KEY); if (drawable.program == null) { drawable.program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources)); } // Use the plaemark's unit square transform matrix. drawable.unitSquareTransform.set(unitSquareTransform); // Configure the drawable according to the placemark's active attributes. Use a color appropriate for the pick // mode. When picking use a unique color associated with the picked object ID. Use the texture associated with // the active attributes' image source and its associated tex coord transform. If the texture is not specified // or not available, draw a simple colored square. drawable.color.set(rc.pickMode ? this.pickColor : this.activeAttributes.imageColor); drawable.texture = this.activeTexture; drawable.enableDepthTest = this.activeAttributes.depthTest; }
@Override public void draw(DrawContext dc) { if (this.program == null || !this.program.useProgram(dc)) { return; // program unspecified or failed to build } if (!dc.unitSquareBuffer().bindBuffer(dc)) { return; // vertex buffer failed to bind } // Use the draw context's pick mode and use the drawable's color. this.program.enablePickMode(dc.pickMode); // Make multi-texture unit 0 active. dc.activeTextureUnit(GLES20.GL_TEXTURE0); // Disable writing to the depth buffer. GLES20.glDepthMask(false); // Use a unit square as the vertex point and vertex tex coord attributes. GLES20.glEnableVertexAttribArray(1 /*vertexTexCoord*/); // only vertexPoint is enabled by default GLES20.glVertexAttribPointer(0 /*vertexPoint*/, 2, GLES20.GL_FLOAT, false, 0, 0); GLES20.glVertexAttribPointer(1 /*vertexTexCoord*/, 2, GLES20.GL_FLOAT, false, 0, 0); // Draw this DrawableScreenTextures. this.doDraw(dc, this); // Draw all DrawableScreenTextures adjacent in the queue that share the same GLSL program. Drawable next; while ((next = dc.peekDrawable()) != null && this.canBatchWith(next)) { // check if the drawable at the front of the queue can be batched DrawableScreenTexture drawable = (DrawableScreenTexture) dc.pollDrawable(); // take it off the queue this.doDraw(dc, drawable); } // Restore the default WorldWind OpenGL state. GLES20.glDepthMask(true); GLES20.glDisableVertexAttribArray(1 /*vertexTexCoord*/); // only vertexPoint is enabled by default }
public void draw(DrawContext dc) { if (this.drawState.program == null || !this.drawState.program.useProgram(dc)) { return; // program unspecified or failed to build
/** * Prepares this placemark's leader for drawing in a subsequent drawing pass. Implementations must be careful not to * leak resources from Placemark into the Drawable. * * @param rc the current render context * @param drawable the Drawable to be prepared */ protected void prepareDrawableLeader(RenderContext rc, DrawableLines drawable) { // Use the basic GLSL program to draw the placemark's leader. drawable.program = (BasicShaderProgram) rc.getShaderProgram(BasicShaderProgram.KEY); if (drawable.program == null) { drawable.program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources)); } // Compute the drawable's vertex points, in Cartesian coordinates relative to the placemark's ground point. drawable.vertexPoints[0] = 0; // groundPoint.x - groundPoint.x drawable.vertexPoints[1] = 0; // groundPoint.y - groundPoint.y drawable.vertexPoints[2] = 0; // groundPoint.z - groundPoint.z drawable.vertexPoints[3] = (float) (placePoint.x - groundPoint.x); drawable.vertexPoints[4] = (float) (placePoint.y - groundPoint.y); drawable.vertexPoints[5] = (float) (placePoint.z - groundPoint.z); // Compute the drawable's modelview-projection matrix, relative to the placemark's ground point. drawable.mvpMatrix.set(rc.modelviewProjection); drawable.mvpMatrix.multiplyByTranslation(groundPoint.x, groundPoint.y, groundPoint.z); // Configure the drawable according to the placemark's active leader attributes. Use a color appropriate for the // pick mode. When picking use a unique color associated with the picked object ID. drawable.color.set(rc.pickMode ? this.pickColor : this.activeAttributes.leaderAttributes.outlineColor); drawable.lineWidth = this.activeAttributes.leaderAttributes.outlineWidth; drawable.enableDepthTest = this.activeAttributes.leaderAttributes.depthTest; }
@Override public void draw(DrawContext dc) { if (this.program == null || !this.program.useProgram(dc)) { return; // program unspecified or failed to build } // Configure the program to draw the specified color. this.program.enableTexture(false); this.program.loadColor(this.color); for (int idx = 0, len = dc.getDrawableTerrainCount(); idx < len; idx++) { // Get the drawable terrain associated with the draw context. DrawableTerrain terrain = dc.getDrawableTerrain(idx); // Use the terrain's vertex point attribute. if (!terrain.useVertexPointAttrib(dc, 0 /*vertexPoint*/)) { continue; // vertex buffer failed to bind } // Use the draw context's modelview projection matrix, transformed to terrain local coordinates. Vec3 terrainOrigin = terrain.getVertexOrigin(); this.mvpMatrix.set(dc.modelviewProjection); this.mvpMatrix.multiplyByTranslation(terrainOrigin.x, terrainOrigin.y, terrainOrigin.z); this.program.loadModelviewProjection(this.mvpMatrix); // Draw the terrain as triangles. terrain.drawTriangles(dc); } } }
@Override protected void doRender(RenderContext rc) { if (rc.terrain.getSector().isEmpty()) { return; // no terrain to render } // Use WorldWind's basic GLSL program. BasicShaderProgram program = (BasicShaderProgram) rc.getShaderProgram(BasicShaderProgram.KEY); if (program == null) { program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources)); } Pool<DrawableTessellation> pool = rc.getDrawablePool(DrawableTessellation.class); Drawable drawable = DrawableTessellation.obtain(pool).set(program, this.color); rc.offerSurfaceDrawable(drawable, 1.0 /*z-order after surface textures*/); } }
drawState.program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources));
@Override public void draw(DrawContext dc) { if (this.program == null || !this.program.useProgram(dc)) { return; // program unspecified or failed to build this.program.enablePickMode(dc.pickMode); this.program.enableTexture(false); this.program.loadColor(this.color); this.mvpMatrix.set(this.offsetMvpMatrix); this.mvpMatrix.multiplyByTranslation(terrainOrigin.x, terrainOrigin.y, terrainOrigin.z); this.program.loadModelviewProjection(this.mvpMatrix);
drawState.program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources));
if (this.program == null || !this.program.useProgram(dc)) { return; // program unspecified or failed to build this.program.enableTexture(false); this.program.loadColor(this.color); this.program.loadModelviewProjection(this.mvpMatrix);
protected void renderTerrainPickedObject(RenderContext rc) { if (rc.terrain.getSector().isEmpty()) { return; // no terrain to pick } // Acquire a unique picked object ID for terrain. int pickedObjectId = rc.nextPickedObjectId(); // Enqueue a drawable for processing on the OpenGL thread that displays terrain in the unique pick color. Pool<DrawableSurfaceColor> pool = rc.getDrawablePool(DrawableSurfaceColor.class); DrawableSurfaceColor drawable = DrawableSurfaceColor.obtain(pool); drawable.color = PickedObject.identifierToUniqueColor(pickedObjectId, drawable.color); drawable.program = (BasicShaderProgram) rc.getShaderProgram(BasicShaderProgram.KEY); if (drawable.program == null) { drawable.program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources)); } rc.offerSurfaceDrawable(drawable, Double.NEGATIVE_INFINITY /*z-order before all other surface drawables*/); // If the pick ray intersects the terrain, enqueue a picked object that associates the terrain drawable with its // picked object ID and the intersection position. if (rc.pickRay != null && rc.terrain.intersect(rc.pickRay, this.pickPoint)) { rc.globe.cartesianToGeographic(this.pickPoint.x, this.pickPoint.y, this.pickPoint.z, this.pickPos); this.pickPos.altitude = 0; // report the actual altitude, which may not lie on the terrain's surface rc.offerPickedObject(PickedObject.fromTerrain(pickedObjectId, this.pickPos)); } }
@Override public void draw(DrawContext dc) { if (this.drawState.program == null || !this.drawState.program.useProgram(dc)) { return; // program unspecified or failed to build this.drawState.program.enablePickMode(dc.pickMode); this.drawState.program.loadModelviewProjection(this.mvpMatrix); this.drawState.program.loadColor(prim.color); this.drawState.program.loadTexCoordMatrix(prim.texCoordMatrix); this.drawState.program.enableTexture(true); } else { this.drawState.program.enableTexture(false);
drawState.program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources));
this.drawState.program.enablePickMode(dc.pickMode); this.drawState.program.loadModelviewProjection(this.mvpMatrix); this.drawState.program.loadColor(prim.color); this.drawState.program.loadTexCoordMatrix(prim.texCoordMatrix); this.drawState.program.enableTexture(true); } else { this.drawState.program.enableTexture(false);
drawable.program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources));