summaryrefslogtreecommitdiffstats
path: root/o3d/samples/bitmap-draw-image.html
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-01 04:21:40 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-01 04:21:40 +0000
commit70c8e97a69ef8806b1812b2cd0ebe831f3792cb6 (patch)
tree4c5b5e5b71ce99f91910b3fd569443f0f07a4e72 /o3d/samples/bitmap-draw-image.html
parent13a8961bf84b7132e2ae588ea644bf7b8012fe75 (diff)
downloadchromium_src-70c8e97a69ef8806b1812b2cd0ebe831f3792cb6.zip
chromium_src-70c8e97a69ef8806b1812b2cd0ebe831f3792cb6.tar.gz
chromium_src-70c8e97a69ef8806b1812b2cd0ebe831f3792cb6.tar.bz2
Update samples to use more utility functions where
appropriate. A few places used pseudoRandom. That is in math.js now so they use that. Other places there is now o3djs.material.createBasicMaterial and o3djs.material.createMaterialFromFile that save 10-20 lines per sample. This CL will require new reference images. There are 2 other things I'd like to consider. #1) Changing every sample that uses shaders/texture-only.shader to use o3djs.material.createConstantMaterial or some variation. The problem with o3djs.material.createConstantMaterial is it requires you pass it a texture if you want a constant textured material. All the samples create the material first, then later add the texture. So, I could add a new o3djs.material.createTextureOnlyMaterial. At the same time that would mean changing those samples from setting stuff on 'texSampler0' to 'emissive' #2) I'd like to change the shader builder so it stops adding "Sampler" to textured materials. As it is if the material uses a color it makes the param called "diffuse" but if it's a texture it makes it "diffuseSampler". That sucks because it means the code has to do crap like var param = material.getParam('diffuse'); if (param) { // it's a color } else { param = material.getParam('diffuseSampler'); if (param) { // it's a texture. } } If we stopped that silliness we could just do var param = material.getParam('diffuse'); if (param) { if (param.isA('o3d.ParamTexture')) { // it's textured. } else { // it's not. } } Unfortunately to fix this requires changing the o3dConverter as well since it uses those conventions. Should we do this? Review URL: http://codereview.chromium.org/182024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/bitmap-draw-image.html')
-rw-r--r--o3d/samples/bitmap-draw-image.html32
1 files changed, 11 insertions, 21 deletions
diff --git a/o3d/samples/bitmap-draw-image.html b/o3d/samples/bitmap-draw-image.html
index 30d2835..a50b1d6 100644
--- a/o3d/samples/bitmap-draw-image.html
+++ b/o3d/samples/bitmap-draw-image.html
@@ -48,7 +48,7 @@ o3djs.require('o3djs.math');
o3djs.require('o3djs.loader');
o3djs.require('o3djs.rendergraph');
o3djs.require('o3djs.primitives');
-o3djs.require('o3djs.effect');
+o3djs.require('o3djs.material');
// Events
// Run the init() once the page has finished loading.
@@ -66,18 +66,12 @@ var g_target;
var g_up;
var g_bitmaps = []; // bitmaps by URL.
-function makeShape(texture, effect) {
- // Create a Material for the effect.
- var myMaterial = g_pack.createObject('Material');
-
- // Set the material's drawList for opaque objects.
- myMaterial.drawList = g_viewInfo.performanceDrawList;
-
- // Apply our effect to this material.
- myMaterial.effect = effect;
-
- // Create the parameters the effect needs on the material.
- effect.createUniformParameters(myMaterial);
+function makeShape(texture) {
+ // Create a material.
+ var myMaterial = o3djs.material.createMaterialFromFile(
+ g_pack,
+ 'shaders/texture-only.shader',
+ g_viewInfo.performanceDrawList);
// Creates a quad.
var myShape = o3djs.primitives.createPlane(g_pack,
@@ -87,10 +81,10 @@ function makeShape(texture, effect) {
1, // quads across
1); // quads down
- // Get the material's sampler parameter and put a sampler on it.
+ // Get the material's sampler parameter, get the sampler on it and set its
+ // texture.
var sampler_param = myMaterial.getParam('texSampler0');
- var sampler = g_pack.createObject('Sampler');
- sampler_param.value = sampler;
+ var sampler = sampler_param.value;
// Set the texture to use.
sampler.texture = texture;
@@ -178,10 +172,6 @@ function initStep2(clientElements) {
g_viewInfo.drawContext.view = view_matrix;
g_viewInfo.drawContext.projection = proj_matrix;
- // Create and load the effect.
- var effect = g_pack.createObject('Effect');
- o3djs.effect.loadEffect(effect, 'shaders/texture-only.shader');
-
var loader = o3djs.loader.createLoader(callback);
loadBitmap(loader, 'shaving_cream_300x300.jpg');
loadBitmap(loader, 'four_pixel.png');
@@ -220,7 +210,7 @@ function initStep2(clientElements) {
texture.drawImage(bitmap1, 0, 0, 0, 300, 300, 1, 0, 0, 150, 150);
texture.drawImage(bitmap2, 0, 0, 0, 2, 2, 2, 0, 0, 75, 75);
- makeShape(texture, effect);
+ makeShape(texture);
}
o3djs.event.addEventListener(o3dElement, 'wheel', scrollMe);
}