1 /***************************************
  2  * Copyright 2011, 2012 GlobWeb contributors.
  3  *
  4  * This file is part of GlobWeb.
  5  *
  6  * GlobWeb is free software: you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as published by
  8  * the Free Software Foundation, version 3 of the License, or
  9  * (at your option) any later version.
 10  *
 11  * GlobWeb is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14  * GNU Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU General Public License
 17  * along with GlobWeb. If not, see <http://www.gnu.org/licenses/>.
 18  ***************************************/
 19 
 20 define( ['./RenderContext', './LineStringRenderable'], function(RenderContext) {
 21  
 22 /**************************************************************************************************************/
 23 
 24 
 25 /** @constructor
 26 	FeatureOverlayManager constructor
 27  */
 28 var FeatureOverlayManager = function()
 29 {
 30 	var gl = RenderContext.gl;
 31 	
 32 	var rttFramebuffer = gl.createFramebuffer();
 33     gl.bindFramebuffer(gl.FRAMEBUFFER, rttFramebuffer);
 34 	rttFramebuffer.width = 512;
 35     rttFramebuffer.height = 512;
 36 	
 37     var renderbuffer = gl.createRenderbuffer();
 38     gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
 39     gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGB5_A1, rttFramebuffer.width, rttFramebuffer.height);
 40 		
 41 	gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, renderbuffer);
 42 
 43 	gl.bindFramebuffer(gl.FRAMEBUFFER, null);
 44 	
 45 	this.frameBuffer = rttFramebuffer;
 46 	
 47 	this.lineStringRenderer = new LineStringRenderer();
 48 }
 49 
 50 /**************************************************************************************************************/
 51 
 52 /*
 53 	Create an overlay texture
 54  */
 55  FeatureOverlayManager.prototype.createOverlayTexture = function( extent )
 56 {
 57 	var gl = RenderContext.gl;
 58 
 59 	gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer);
 60 	gl.clear(gl.COLOR_BUFFER_BIT);
 61 	
 62 	var projectionMatrix = mat4.create();
 63 	mat4.ortho( extent[0], extent[1], extent[2], extent[3], -10, 10, projectionMatrix );
 64 	var viewMatrix = mat4.create();
 65 	mat4.identity( viewMatrix );
 66 	
 67 	this.lineStringRenderer.render( viewMatrix, projectionMatrix );
 68 
 69 	// Create the texture, and upload the image
 70 	//this.texture = TilePool.createGLTexture(this.image);
 71 	var texture = gl.createTexture();
 72 /*	var image = new Uint8Array(4);
 73 	image[0] = 0;
 74 	image[1] = 255;
 75 	image[2] = 0;
 76 	image[3] = 45;*/
 77 	gl.bindTexture(gl.TEXTURE_2D, texture);
 78 	gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA,0,0,512,512,0);
 79 	//gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, image);
 80 	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
 81 	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
 82 	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
 83 	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
 84 	gl.generateMipmap(gl.TEXTURE_2D);
 85 
 86 	gl.bindFramebuffer(gl.FRAMEBUFFER, null);
 87 	
 88 	return texture;
 89 }
 90 
 91 /**************************************************************************************************************/
 92 
 93 return FeatureOverlayManager;
 94 
 95 });
 96