Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for Materials to take canvas uniform values #2667

Merged
merged 1 commit into from
Apr 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Change Log
* Fixed crash when loading KML GroundOverlays that spanned 360 degrees. [#2639](https://github.com/AnalyticalGraphicsInc/cesium/pull/2639)
* Fixed `Geocoder` styling issue in Safari. [#2658](https://github.com/AnalyticalGraphicsInc/cesium/pull/2658).
* Added number of cached shaders to the `CesiumInspector` debugging widget.
* Entity `material` properties and `Material` uniform values can now take a `canvas` element in addition to an image or url.

### 1.8 - 2015-04-01

Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/createMaterialPropertyDescriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define([
return new ColorMaterialProperty(value);
}

if (typeof value === 'string') {
if (typeof value === 'string' || value instanceof HTMLCanvasElement) {
var result = new ImageMaterialProperty();
result.image = value;
return result;
Expand Down
9 changes: 7 additions & 2 deletions Source/Scene/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,18 @@ define([
if (defined(newTexture)) {
Material._textureCache.releaseTexture(material._texturePaths[uniformId]);
material._textures[uniformId] = newTexture;
} else {
} else if (typeof uniformValue === 'string') {
when(loadImage(uniformValue), function(image) {
material._loadedImages.push({
id : uniformId,
image : image
});
});
} else if (uniformValue instanceof HTMLCanvasElement) {
material._loadedImages.push({
id : uniformId,
image : uniformValue
});
}

material._texturePaths[uniformId] = uniformValue;
Expand Down Expand Up @@ -853,7 +858,7 @@ define([
uniformType = 'float';
} else if (type === 'boolean') {
uniformType = 'bool';
} else if (type === 'string') {
} else if (type === 'string' || uniformValue instanceof HTMLCanvasElement) {
if (/^([rgba]){1,4}$/i.test(uniformValue)) {
uniformType = 'channels';
} else if (uniformValue === Material.DefaultCubeMapId) {
Expand Down
22 changes: 22 additions & 0 deletions Specs/Scene/MaterialSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,28 @@ defineSuite([
expect(pixel).not.toEqual([0, 0, 0, 0]);
});

it('creates a material with an image canvas uniform', function() {
var canvas = document.createElement('canvas');
var context2D = canvas.getContext('2d');
context2D.width = 1;
context2D.height = 1;
context2D.fillStyle = 'rgb(0,0,255)';
context2D.fillRect(0, 0, 1, 1);

var material = new Material({
strict : true,
fabric : {
type : 'DiffuseMap',
uniforms : {
image : canvas
}
}
});

var pixel = renderMaterial(material);
expect(pixel).not.toEqual([0, 0, 0, 0]);
});

it('creates a material with a cube map uniform', function() {
var material = new Material({
strict : true,
Expand Down