Skip to content

Commit

Permalink
use same types as structarray
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Mar 16, 2016
1 parent fe8dad8 commit 2fd662e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 30 deletions.
2 changes: 0 additions & 2 deletions js/data/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ Bucket.create = function(options) {
return new Classes[options.layer.type](options);
};

Bucket.AttributeType = Buffer.AttributeType;


/**
* The maximum extent of a feature that can be safely stored in the buffer.
Expand Down
2 changes: 1 addition & 1 deletion js/data/bucket/circle_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CircleBucket.prototype.shaderInterfaces = {
attributes: [{
name: 'pos',
components: 2,
type: Bucket.AttributeType.SHORT,
type: 'Int16',
value: [
'(x * 2) + ((extrudeX + 1) / 2)',
'(y * 2) + ((extrudeY + 1) / 2)'
Expand Down
2 changes: 1 addition & 1 deletion js/data/bucket/fill_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FillBucket.prototype.shaderInterfaces = {
attributes: [{
name: 'pos',
components: 2,
type: Bucket.AttributeType.SHORT,
type: 'Int16',
value: ['x', 'y']
}]
}
Expand Down
4 changes: 2 additions & 2 deletions js/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ LineBucket.prototype.shaderInterfaces = {
attributes: [{
name: 'pos',
components: 2,
type: Bucket.AttributeType.SHORT,
type: 'Int16',
value: [
'(point.x << 1) | tx',
'(point.y << 1) | ty'
]
}, {
name: 'data',
components: 4,
type: Bucket.AttributeType.UNSIGNED_BYTE,
type: 'Uint8',
value: [
// add 128 to store an byte in an unsigned byte
'Math.round(' + EXTRUDE_SCALE + ' * extrude.x) + 128',
Expand Down
14 changes: 7 additions & 7 deletions js/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ var shaderAttributeArgs = ['x', 'y', 'ox', 'oy', 'tx', 'ty', 'minzoom', 'maxzoom
var shaderAttributes = [{
name: 'pos',
components: 2,
type: Bucket.AttributeType.SHORT,
type: 'Int16',
value: ['x', 'y']
}, {
name: 'offset',
components: 2,
type: Bucket.AttributeType.SHORT,
type: 'Int16',
value: [
'Math.round(ox * 64)', // use 1/64 pixels for placement
'Math.round(oy * 64)'
]
}, {
name: 'data1',
components: 4,
type: Bucket.AttributeType.UNSIGNED_BYTE,
type: 'Uint8',
value: [
'tx / 4', // tex
'ty / 4', // tex
Expand All @@ -61,7 +61,7 @@ var shaderAttributes = [{
}, {
name: 'data2',
components: 2,
type: Bucket.AttributeType.UNSIGNED_BYTE,
type: 'Uint8',
value: [
'(minzoom || 0) * 10', // minzoom
'Math.min(maxzoom || 25, 25) * 10' // minzoom
Expand Down Expand Up @@ -92,20 +92,20 @@ SymbolBucket.prototype.shaderInterfaces = {
attributes: [{
name: 'pos',
components: 2,
type: Bucket.AttributeType.SHORT,
type: 'Int16',
value: [ 'point.x', 'point.y' ]
}, {
name: 'extrude',
components: 2,
type: Bucket.AttributeType.SHORT,
type: 'Int16',
value: [
'Math.round(extrude.x)',
'Math.round(extrude.y)'
]
}, {
name: 'data',
components: 2,
type: Bucket.AttributeType.UNSIGNED_BYTE,
type: 'Uint8',
value: [
'maxZoom * 10',
'placementZoom * 10'
Expand Down
23 changes: 9 additions & 14 deletions js/data/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,17 @@ Buffer.prototype.destroy = function(gl) {
};

/**
* @enum {{size: number, name: string}} BufferAttributeType
* @enum {string} BufferAttributeType
* @private
* @readonly
*/
Buffer.AttributeType = {
BYTE: 'Int8',
UNSIGNED_BYTE: 'Uint8',
SHORT: 'Int16',
UNSIGNED_SHORT: 'Uint16'
var AttributeType = {
Int8: 'BYTE',
Uint8: 'UNSIGNED_BYTE',
Int16: 'SHORT',
Uint16: 'UNSIGNED_SHORT'
};

var convertType = {};
for (var t in Buffer.AttributeType) {
convertType[Buffer.AttributeType[t]] = t;
}

/**
* Set the attribute pointers in a WebGL context according to the buffer's attribute layout
* @private
Expand All @@ -80,7 +75,7 @@ Buffer.prototype.setAttribPointers = function(gl, shader, offset) {
var attrib = this.attributes[i];

gl.vertexAttribPointer(
shader['a_' + attrib.name], attrib.components, gl[convertType[attrib.type]],
shader['a_' + attrib.name], attrib.components, gl[AttributeType[attrib.type]],
false, this.itemSize, offset + attrib.offset);
}
};
Expand All @@ -99,11 +94,11 @@ Buffer.BufferType = {
* An `BufferType.ELEMENT` buffer holds indicies of a corresponding `BufferType.VERTEX` buffer.
* These indicies are stored in the `BufferType.ELEMENT` buffer as `UNSIGNED_SHORT`s.
*
* @property {BufferAttributeType}
* @property {string}
* @private
* @readonly
*/
Buffer.ELEMENT_ATTRIBUTE_TYPE = Buffer.AttributeType.UNSIGNED_SHORT;
Buffer.ELEMENT_ATTRIBUTE_TYPE = 'Uint16';

/**
* WebGL performs best if vertex attribute offsets are aligned to 4 byte boundaries.
Expand Down
5 changes: 2 additions & 3 deletions test/js/data/bucket.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var test = require('prova');
var Buffer = require('../../../js/data/buffer');
var Bucket = require('../../../js/data/bucket');
var util = require('../../../js/util/util');

Expand All @@ -25,12 +24,12 @@ test('Bucket', function(t) {

attributes: [{
name: 'map',
type: Buffer.AttributeType.SHORT,
type: 'Int16',
value: ['x']
}, {
name: 'box',
components: 2,
type: Buffer.AttributeType.SHORT,
type: 'Int16',
value: ['x * 2', 'y * 2']
}]
}
Expand Down

0 comments on commit 2fd662e

Please sign in to comment.