this._init = function (arg) { var prog = vgl.shaderProgram(), posAttr = vgl.vertexAttribute('pos'), fillColorAttr = vgl.vertexAttribute('fillColor'), fillOpacityAttr = vgl.vertexAttribute('fillOpacity'), modelViewUniform = new vgl.modelViewUniform('modelViewMatrix'), projectionUniform = new vgl.projectionUniform('projectionMatrix'), vertexShader = createVertexShader(), fragmentShader = createFragmentShader(), blend = vgl.blend(), geom = vgl.geometryData(), sourcePositions = vgl.sourceDataP3fv({'name': 'pos'}), sourceFillColor = vgl.sourceDataAnyfv( 3, vgl.vertexAttributeKeysIndexed.Two, {'name': 'fillColor'}), sourceFillOpacity = vgl.sourceDataAnyfv( 1, vgl.vertexAttributeKeysIndexed.Three, {'name': 'fillOpacity'}), trianglePrimitive = vgl.triangles(); prog.addVertexAttribute(posAttr, vgl.vertexAttributeKeys.Position); prog.addVertexAttribute(fillColorAttr, vgl.vertexAttributeKeysIndexed.Two); prog.addVertexAttribute(fillOpacityAttr, vgl.vertexAttributeKeysIndexed.Three); prog.addUniform(modelViewUniform); prog.addUniform(projectionUniform); prog.addShader(fragmentShader); prog.addShader(vertexShader); m_material.addAttribute(prog); m_material.addAttribute(blend); m_actor.setMaterial(m_material); m_actor.setMapper(m_mapper); geom.addSource(sourcePositions); geom.addSource(sourceFillColor); geom.addSource(sourceFillOpacity); geom.addPrimitive(trianglePrimitive); m_mapper.setGeometryData(geom); s_init.call(m_this, arg); };
this._init = function () { var prog = vgl.shaderProgram(), vertexShader = createVertexShader(), fragmentShader = createFragmentShader(), posAttr = vgl.vertexAttribute('pos'), unitAttr = vgl.vertexAttribute('unit'), radAttr = vgl.vertexAttribute('rad'), strokeWidthAttr = vgl.vertexAttribute('strokeWidth'), fillColorAttr = vgl.vertexAttribute('fillColor'), fillAttr = vgl.vertexAttribute('fill'), strokeColorAttr = vgl.vertexAttribute('strokeColor'), strokeAttr = vgl.vertexAttribute('stroke'), fillOpacityAttr = vgl.vertexAttribute('fillOpacity'), strokeOpacityAttr = vgl.vertexAttribute('strokeOpacity'), modelViewUniform = new vgl.modelViewUniform('modelViewMatrix'), projectionUniform = new vgl.projectionUniform('projectionMatrix'), mat = vgl.material(), blend = vgl.blend(), geom = vgl.geometryData(), sourcePositions = vgl.sourceDataP3fv({'name': 'pos'}), sourceUnits = vgl.sourceDataAnyfv( 2, vgl.vertexAttributeKeysIndexed.One, {'name': 'unit'}), sourceRadius = vgl.sourceDataAnyfv( 1, vgl.vertexAttributeKeysIndexed.Two, {'name': 'rad'}), sourceStrokeWidth = vgl.sourceDataAnyfv( 1, vgl.vertexAttributeKeysIndexed.Three, {'name': 'strokeWidth'}), sourceFillColor = vgl.sourceDataAnyfv( 3, vgl.vertexAttributeKeysIndexed.Four, {'name': 'fillColor'}), sourceFill = vgl.sourceDataAnyfv( 1, vgl.vertexAttributeKeysIndexed.Five, {'name': 'fill'}), sourceStrokeColor = vgl.sourceDataAnyfv( 3, vgl.vertexAttributeKeysIndexed.Six, {'name': 'strokeColor'}), sourceStroke = vgl.sourceDataAnyfv( 1, vgl.vertexAttributeKeysIndexed.Seven, {'name': 'stroke'}), sourceAlpha = vgl.sourceDataAnyfv( 1, vgl.vertexAttributeKeysIndexed.Eight, {'name': 'fillOpacity'}), sourceStrokeOpacity = vgl.sourceDataAnyfv( 1, vgl.vertexAttributeKeysIndexed.Nine, {'name': 'strokeOpacity'}), primitive = new vgl.triangles(); if (m_primitiveShape === 'sprite') { primitive = new vgl.points(); } m_pixelWidthUniform = new vgl.floatUniform('pixelWidth', 2.0 / m_this.renderer().width()); m_aspectUniform = new vgl.floatUniform('aspect', m_this.renderer().width() / m_this.renderer().height()); s_init.call(m_this, arg); m_mapper = vgl.mapper({dynamicDraw: m_dynamicDraw}); // TODO: Right now this is ugly but we will fix it. prog.addVertexAttribute(posAttr, vgl.vertexAttributeKeys.Position); if (m_primitiveShape !== 'sprite') { prog.addVertexAttribute(unitAttr, vgl.vertexAttributeKeysIndexed.One); } prog.addVertexAttribute(radAttr, vgl.vertexAttributeKeysIndexed.Two); prog.addVertexAttribute(strokeWidthAttr, vgl.vertexAttributeKeysIndexed.Three); prog.addVertexAttribute(fillColorAttr, vgl.vertexAttributeKeysIndexed.Four); prog.addVertexAttribute(fillAttr, vgl.vertexAttributeKeysIndexed.Five); prog.addVertexAttribute(strokeColorAttr, vgl.vertexAttributeKeysIndexed.Six); prog.addVertexAttribute(strokeAttr, vgl.vertexAttributeKeysIndexed.Seven); prog.addVertexAttribute(fillOpacityAttr, vgl.vertexAttributeKeysIndexed.Eight); prog.addVertexAttribute(strokeOpacityAttr, vgl.vertexAttributeKeysIndexed.Nine); prog.addUniform(m_pixelWidthUniform); prog.addUniform(m_aspectUniform); prog.addUniform(modelViewUniform); prog.addUniform(projectionUniform); prog.addShader(fragmentShader); prog.addShader(vertexShader); mat.addAttribute(prog); mat.addAttribute(blend); m_actor = vgl.actor(); m_actor.setMaterial(mat); m_actor.setMapper(m_mapper); geom.addSource(sourcePositions); geom.addSource(sourceUnits); geom.addSource(sourceRadius); geom.addSource(sourceStrokeWidth); geom.addSource(sourceFillColor); geom.addSource(sourceFill); geom.addSource(sourceStrokeColor); geom.addSource(sourceStroke); geom.addSource(sourceAlpha); geom.addSource(sourceStrokeOpacity); geom.addPrimitive(primitive); m_mapper.setGeometryData(geom); };
this._init = function (arg) { var blend = vgl.blend(), prog = vgl.shaderProgram(), mat = vgl.material(), tex = vgl.lookupTable(), geom = vgl.geometryData(), modelViewUniform = new vgl.modelViewUniform('modelViewMatrix'), projectionUniform = new vgl.projectionUniform('projectionMatrix'), samplerUniform = new vgl.uniform(vgl.GL.INT, 'sampler2d'), vertexShader = createVertexShader(), fragmentShader = createFragmentShader(), posAttr = vgl.vertexAttribute('pos'), valueAttr = vgl.vertexAttribute('value'), opacityAttr = vgl.vertexAttribute('opacity'), sourcePositions = vgl.sourceDataP3fv({'name': 'pos'}), sourceValues = vgl.sourceDataAnyfv( 1, vgl.vertexAttributeKeysIndexed.One, {'name': 'value'}), sourceOpacity = vgl.sourceDataAnyfv( 1, vgl.vertexAttributeKeysIndexed.Two, {'name': 'opacity'}), primitive = new vgl.triangles(); s_init.call(m_this, arg); m_mapper = vgl.mapper({dynamicDraw: m_dynamicDraw}); prog.addVertexAttribute(posAttr, vgl.vertexAttributeKeys.Position); prog.addVertexAttribute(valueAttr, vgl.vertexAttributeKeysIndexed.One); prog.addVertexAttribute(opacityAttr, vgl.vertexAttributeKeysIndexed.Two); prog.addUniform(modelViewUniform); prog.addUniform(projectionUniform); m_minColorUniform = new vgl.uniform(vgl.GL.FLOAT_VEC4, 'minColor'); prog.addUniform(m_minColorUniform); m_maxColorUniform = new vgl.uniform(vgl.GL.FLOAT_VEC4, 'maxColor'); prog.addUniform(m_maxColorUniform); /* steps is always an integer, but it is more efficient if we use a float */ m_stepsUniform = new vgl.uniform(vgl.GL.FLOAT, 'steps'); prog.addUniform(m_stepsUniform); m_steppedUniform = new vgl.uniform(vgl.GL.BOOL, 'stepped'); prog.addUniform(m_steppedUniform); prog.addShader(fragmentShader); prog.addShader(vertexShader); prog.addUniform(samplerUniform); tex.setTextureUnit(m_textureUnit); samplerUniform.set(m_textureUnit); m_material = mat; m_material.addAttribute(prog); m_material.addAttribute(blend); m_texture = tex; m_material.addAttribute(m_texture); m_actor = vgl.actor(); m_actor.setMaterial(m_material); m_actor.setMapper(m_mapper); geom.addSource(sourcePositions); geom.addSource(sourceValues); geom.addSource(sourceOpacity); geom.addPrimitive(primitive); /* We don't need vgl to comptue bounds, so make the geo.computeBounds just * set them to 0. */ geom.computeBounds = function () { geom.setBounds(0, 0, 0, 0, 0, 0); }; m_mapper.setGeometryData(geom); };
function createGLPolygons() { var posFunc = null, fillColorFunc = null, fillOpacityFunc = null, buffers = vgl.DataBuffers(1024), sourcePositions = vgl.sourceDataP3fv(), sourceFillColor = vgl.sourceDataAnyfv(3, vgl.vertexAttributeKeysIndexed.Two), sourceFillOpacity = vgl.sourceDataAnyfv(1, vgl.vertexAttributeKeysIndexed.Three), trianglePrimitive = vgl.triangles(), geom = vgl.geometryData(), triangles = [], target_gcs = m_this.gcs(), map_gcs = m_this.layer().map().gcs(), color; posFunc = m_this.position(); fillColorFunc = m_this.style.get('fillColor'); fillOpacityFunc = m_this.style.get('fillOpacity'); buffers.create('pos', 3); buffers.create('indices', 1); buffers.create('fillColor', 3); buffers.create('fillOpacity', 1); m_this.data().forEach(function (item, itemIndex) { var polygon, geometry, numPts, start, i, vertex, j; function position(d, i) { var c = posFunc(d, i, item, itemIndex); return [c.x, c.y, c.z || 0]; } polygon = m_this.polygon()(item, itemIndex); polygon.outer = polygon.outer || []; polygon.inner = polygon.inner || []; // expand to a geojson polygon geometry geometry = [(polygon.outer || []).map(position)]; (polygon.inner || []).forEach(function (hole) { geometry.push(hole.map(position)); }); // convert to an earcut geometry geometry = earcut.flatten(geometry); // tranform to map gcs geometry.vertices = transform.transformCoordinates( target_gcs, map_gcs, geometry.vertices, geometry.dimensions ); // triangulate triangles = earcut(geometry.vertices, geometry.holes, geometry.dimensions); // append to buffers numPts = triangles.length; start = buffers.alloc(triangles.length); for (i = 0; i < numPts; i += 1) { j = triangles[i] * 3; vertex = geometry.vertices.slice(triangles[i] * 3, j + 3); buffers.write('pos', vertex, start + i, 1); buffers.write('indices', [i], start + i, 1); color = fillColorFunc(vertex, i, item, itemIndex); buffers.write( 'fillColor', [color.r, color.g, color.b], start + i, 1 ); buffers.write( 'fillOpacity', [fillOpacityFunc(vertex, i, item, itemIndex)], start + i, 1 ); } }); sourcePositions.pushBack(buffers.get('pos')); geom.addSource(sourcePositions); sourceFillColor.pushBack(buffers.get('fillColor')); geom.addSource(sourceFillColor); sourceFillOpacity.pushBack(buffers.get('fillOpacity')); geom.addSource(sourceFillOpacity); trianglePrimitive.setIndices(buffers.get('indices')); geom.addPrimitive(trianglePrimitive); m_mapper.setGeometryData(geom); }