Comparing version
@@ -63,8 +63,9 @@ /** | ||
* | ||
* @param {WebGLRenderingContext} gl | ||
* @param {WebGLRenderingContext | WebGL2RenderingContext} gl | ||
* @param {?Number} location Положение аттрибута для связывания данных с переменными в шейдере | ||
* @param {?BufferBindOptions} options Параметры передаваемые в функцию vertexAttribPointer, если их нет, | ||
* то используются параметры конкретного буфера. Параметры должны быть переданы все. | ||
* @param {?ANGLE_instanced_arrays} instancesExt Экстеншн для работы с instanced буферами, | ||
*/ | ||
bind(gl, location, options) { | ||
bind(gl, location, options, instancesExt) { | ||
if (!this._glBuffer) { | ||
@@ -77,2 +78,3 @@ this.prepare(gl); | ||
location = location || 0; | ||
options = options || this.options; | ||
@@ -84,3 +86,12 @@ | ||
if (options.instanceDivisor) { | ||
gl.vertexAttribDivisor(location, options.instanceDivisor); | ||
if (gl instanceof WebGLRenderingContext) { | ||
if (instancesExt) { | ||
instancesExt.vertexAttribDivisorANGLE(location, options.instanceDivisor); | ||
} else { | ||
console.error('Can\'t set up instanced attribute divisor. ' + | ||
'Missing ANGLE_instanced_arrays extension'); | ||
} | ||
} else { | ||
gl.vertexAttribDivisor(location, options.instanceDivisor); | ||
} | ||
} | ||
@@ -87,0 +98,0 @@ } else if (this.type === Buffer.ElementArrayBuffer) { |
@@ -33,4 +33,4 @@ import Buffer from './Buffer'; | ||
*/ | ||
bind(gl, location) { | ||
this._buffer.bind(gl, location, this.options); | ||
bind(gl, location, instancesExt) { | ||
this._buffer.bind(gl, location, this.options, instancesExt); | ||
} | ||
@@ -37,0 +37,0 @@ } |
{ | ||
"name": "2gl", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "WebGL library for 2GIS projects", | ||
@@ -55,5 +55,4 @@ "repository": { | ||
"test": "npm run build:shaders && BABEL_ENV=cov nyc --reporter=lcov --reporter=text mocha --require=test/babelRegister.js test/*.spec.js test/**/*.spec.js", | ||
"test:dev": "npm run build:shaders && ./node_modules/.bin/_mocha --require=test/babelRegister.js -w test/*.spec.js test/**/*.spec.js", | ||
"pub": "npm run build && npm run copy && npm publish && git clean -d -f" | ||
"test:dev": "npm run build:shaders && ./node_modules/.bin/_mocha --require=test/babelRegister.js -w test/*.spec.js test/**/*.spec.js" | ||
} | ||
} |
# 2gl [](https://travis-ci.org/2gis/2gl) [](https://coveralls.io/github/2gis/2gl?branch=master) | ||
Узкоспециализированная библиотека WebGL для использования в проектах 2GIS | ||
@@ -6,4 +7,4 @@ | ||
* Для работы с матрицами и векторами используется библиотека [glMatrix](http://glmatrix.net/) | ||
* Работа с геометрическими объектами, например, Plane, Line3, Ray, взята из [three.js](http://threejs.org/) | ||
- Для работы с матрицами и векторами используется библиотека [glMatrix](http://glmatrix.net/) | ||
- Работа с геометрическими объектами, например, Plane, Line3, Ray, взята из [three.js](http://threejs.org/) | ||
@@ -13,3 +14,3 @@ На данный момент может работать со следующими типами объектов для отображения: | ||
1. [Basic mesh](https://2gis.github.io/2gl/docs/BasicMeshMaterial.html) - меш, закрашивается в один цвет | ||
2. [Complex mesh](https://2gis.github.io/2gl/docs/ComplexMeshMaterial.html) - меш, для которого можно устанавить: цвета для каждой из вершин, освещение, текстуру и определять для какой из вершин будет использоваться текстура | ||
2. [Complex mesh](https://2gis.github.io/2gl/docs/ComplexMeshMaterial.html) - меш, для которого можно установить: цвета для каждой из вершин, освещение, текстуру и определять для какой из вершин будет использоваться текстура | ||
3. [Sprite](https://2gis.github.io/2gl/docs/Sprite.html) - спрайт, к камере расположен всегда одной гранью, удалённость не влияет на размеры изображения | ||
@@ -19,33 +20,73 @@ 4. [MultiSprite](https://2gis.github.io/2gl/docs/MultiSprite.html) - мультиспрайт представляет собой множество спрайтов, которые рисуются в один draw call | ||
#### Examples | ||
* [Basic mesh performance](https://2gis.github.io/2gl/examples/basicMeshPerformance) | ||
* [Complex mesh performance](https://2gis.github.io/2gl/examples/complexMeshPerformance) | ||
* [Sprite performance](https://2gis.github.io/2gl/examples/spritePerformance) | ||
* [MultiSprite performance](https://2gis.github.io/2gl/examples/multiSpritePerformance) | ||
- [Basic mesh performance](https://2gis.github.io/2gl/examples/basicMeshPerformance) | ||
- [Complex mesh performance](https://2gis.github.io/2gl/examples/complexMeshPerformance) | ||
- [Sprite performance](https://2gis.github.io/2gl/examples/spritePerformance) | ||
- [MultiSprite performance](https://2gis.github.io/2gl/examples/multiSpritePerformance) | ||
#### Установка | ||
* `npm install 2gl` | ||
- `npm install 2gl` | ||
#### Подключение | ||
Есть несколько способов подключения библиотеки: | ||
* Напрямую через тег, скрипт `2gl.js` лежит в папке `dist` и содержит все компоненты библиотеки: | ||
- Напрямую через тег, скрипт `2gl.js` лежит в папке `dist` и содержит все компоненты библиотеки: | ||
```html | ||
<script src="2gl.js"></script> | ||
``` | ||
* Если вы используете сборщики, например, `browserify` или `webpack`: | ||
- Если вы используете сборщики, например, `browserify` или `webpack`: | ||
```js | ||
var dgl = require('2gl'); // CommonJS | ||
import dgl from '2gl'; // ES6 | ||
var dgl = require("2gl"); // CommonJS | ||
import dgl from "2gl"; // ES6 | ||
``` | ||
* Можно подключать только нужные компоненты для уменьшения размера: | ||
- Можно подключать только нужные компоненты для уменьшения размера: | ||
```js | ||
var Mesh = require('2gl/Mesh'); | ||
var AmbientLight = require('2gl/lights/AmbientLight'); | ||
var Mesh = require("2gl/Mesh"); | ||
var AmbientLight = require("2gl/lights/AmbientLight"); | ||
``` | ||
#### Development | ||
* `npm install` | ||
* `npm start` | ||
- `npm install` | ||
- `npm start` | ||
#### Checking examples locally | ||
- Install `http-server` | ||
- Run `http-server` at the root project directory | ||
- Open http://localhost:8080/ and navigate to some `*.html` demo at the `examples` directory | ||
#### Release | ||
* `npm version patch` - поднять патч версию | ||
* `npm run pub` - собрать проект, отправить в npm, вернуть в исходное состояние | ||
If you plan to release a new version from your branch | ||
- Bump version via `npm version major | minor | patch` | ||
- Merge your branch into master | ||
- [Create a new release](https://github.com/2gis/2gl/releases), this will run the release workflow | ||
#### Beta-release | ||
Beta-release is suitable to perform some checks/integrations with npm-package. | ||
It releases the same npm package as a regular release, but in the beta tag, which do not update latest version on npm. | ||
To make beta-release you should create a tag with a current version in `package.json` and suffix, e.g. | ||
``` | ||
npm version 0.12.0-foo-bar | ||
``` | ||
And then push tag. | ||
``` | ||
git push --tags | ||
``` | ||
Pushed tag will run the beta-release workflow. |
@@ -63,8 +63,9 @@ /** | ||
* | ||
* @param {WebGLRenderingContext} gl | ||
* @param {WebGLRenderingContext | WebGL2RenderingContext} gl | ||
* @param {?Number} location Положение аттрибута для связывания данных с переменными в шейдере | ||
* @param {?BufferBindOptions} options Параметры передаваемые в функцию vertexAttribPointer, если их нет, | ||
* то используются параметры конкретного буфера. Параметры должны быть переданы все. | ||
* @param {?ANGLE_instanced_arrays} instancesExt Экстеншн для работы с instanced буферами, | ||
*/ | ||
bind(gl, location, options) { | ||
bind(gl, location, options, instancesExt) { | ||
if (!this._glBuffer) { | ||
@@ -77,2 +78,3 @@ this.prepare(gl); | ||
location = location || 0; | ||
options = options || this.options; | ||
@@ -84,3 +86,12 @@ | ||
if (options.instanceDivisor) { | ||
gl.vertexAttribDivisor(location, options.instanceDivisor); | ||
if (gl instanceof WebGLRenderingContext) { | ||
if (instancesExt) { | ||
instancesExt.vertexAttribDivisorANGLE(location, options.instanceDivisor); | ||
} else { | ||
console.error('Can\'t set up instanced attribute divisor. ' + | ||
'Missing ANGLE_instanced_arrays extension'); | ||
} | ||
} else { | ||
gl.vertexAttribDivisor(location, options.instanceDivisor); | ||
} | ||
} | ||
@@ -87,0 +98,0 @@ } else if (this.type === Buffer.ElementArrayBuffer) { |
@@ -33,4 +33,4 @@ import Buffer from './Buffer'; | ||
*/ | ||
bind(gl, location) { | ||
this._buffer.bind(gl, location, this.options); | ||
bind(gl, location, instancesExt) { | ||
this._buffer.bind(gl, location, this.options, instancesExt); | ||
} | ||
@@ -37,0 +37,0 @@ } |
@@ -18,5 +18,4 @@ /** | ||
* WebGL экстеншен, в котором был инициализирован буфер. | ||
* Используется только для удаления vao, подумать хорошо, прежде чем использовать для чего-то ещё. | ||
*/ | ||
this._ext = null; | ||
this._vaoExt = null; | ||
} | ||
@@ -30,5 +29,6 @@ | ||
bind(state) { | ||
const ext = state.extensions.OES_vertex_array_object; | ||
const vaoExt = state.extensions.OES_vertex_array_object; | ||
const instancesExt = state.extensions.ANGLE_instanced_arrays; | ||
this._bind(state.gl, ext); | ||
this._bind(state.gl, vaoExt, instancesExt); | ||
@@ -65,5 +65,5 @@ return this; | ||
_bind(gl, ext) { | ||
_bind(gl, vaoExt, instancesExt) { | ||
if (!this._vao) { | ||
this._prepare(gl, ext); | ||
this._prepare(gl, vaoExt, instancesExt); | ||
} else { | ||
@@ -74,5 +74,5 @@ this._glBindVertexArray(this._vao); | ||
_prepare(gl, ext) { | ||
_prepare(gl, vaoExt, instancesExt) { | ||
this._gl = gl; | ||
this._ext = ext; | ||
this._vaoExt = vaoExt; | ||
@@ -91,3 +91,3 @@ this._vao = this._glCreateVertexArray(); | ||
} | ||
attributes[name].bind(gl, shaderAttribute.location, undefined); | ||
attributes[name].bind(gl, shaderAttribute.location, instancesExt); | ||
} | ||
@@ -98,3 +98,3 @@ } | ||
const gl = this._gl; | ||
const ext = this._ext; | ||
const ext = this._vaoExt; | ||
if (this._isWebGL2(gl)) { | ||
@@ -110,3 +110,3 @@ return gl.createVertexArray(); | ||
const gl = this._gl; | ||
const ext = this._ext; | ||
const ext = this._vaoExt; | ||
if (this._isWebGL2(gl)) { | ||
@@ -124,3 +124,3 @@ gl.bindVertexArray(vao); | ||
const gl = this._gl; | ||
const ext = this._ext; | ||
const ext = this._vaoExt; | ||
if (this._isWebGL2(gl)) { | ||
@@ -127,0 +127,0 @@ gl.deleteVertexArray(vao); |
24
Vao.js
@@ -18,5 +18,4 @@ /** | ||
* WebGL экстеншен, в котором был инициализирован буфер. | ||
* Используется только для удаления vao, подумать хорошо, прежде чем использовать для чего-то ещё. | ||
*/ | ||
this._ext = null; | ||
this._vaoExt = null; | ||
} | ||
@@ -30,5 +29,6 @@ | ||
bind(state) { | ||
const ext = state.extensions.OES_vertex_array_object; | ||
const vaoExt = state.extensions.OES_vertex_array_object; | ||
const instancesExt = state.extensions.ANGLE_instanced_arrays; | ||
this._bind(state.gl, ext); | ||
this._bind(state.gl, vaoExt, instancesExt); | ||
@@ -65,5 +65,5 @@ return this; | ||
_bind(gl, ext) { | ||
_bind(gl, vaoExt, instancesExt) { | ||
if (!this._vao) { | ||
this._prepare(gl, ext); | ||
this._prepare(gl, vaoExt, instancesExt); | ||
} else { | ||
@@ -74,5 +74,5 @@ this._glBindVertexArray(this._vao); | ||
_prepare(gl, ext) { | ||
_prepare(gl, vaoExt, instancesExt) { | ||
this._gl = gl; | ||
this._ext = ext; | ||
this._vaoExt = vaoExt; | ||
@@ -91,3 +91,3 @@ this._vao = this._glCreateVertexArray(); | ||
} | ||
attributes[name].bind(gl, shaderAttribute.location, undefined); | ||
attributes[name].bind(gl, shaderAttribute.location, instancesExt); | ||
} | ||
@@ -98,3 +98,3 @@ } | ||
const gl = this._gl; | ||
const ext = this._ext; | ||
const ext = this._vaoExt; | ||
if (this._isWebGL2(gl)) { | ||
@@ -110,3 +110,3 @@ return gl.createVertexArray(); | ||
const gl = this._gl; | ||
const ext = this._ext; | ||
const ext = this._vaoExt; | ||
if (this._isWebGL2(gl)) { | ||
@@ -124,3 +124,3 @@ gl.bindVertexArray(vao); | ||
const gl = this._gl; | ||
const ext = this._ext; | ||
const ext = this._vaoExt; | ||
if (this._isWebGL2(gl)) { | ||
@@ -127,0 +127,0 @@ gl.deleteVertexArray(vao); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
814146
1.4%135
2.27%8349
0.26%90
83.67%