From 70c8e97a69ef8806b1812b2cd0ebe831f3792cb6 Mon Sep 17 00:00:00 2001 From: "gman@google.com" Date: Tue, 1 Sep 2009 04:21:40 +0000 Subject: 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 --- o3d/samples/displayfps.html | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'o3d/samples/displayfps.html') diff --git a/o3d/samples/displayfps.html b/o3d/samples/displayfps.html index c873eff..a67fbe07 100644 --- a/o3d/samples/displayfps.html +++ b/o3d/samples/displayfps.html @@ -54,7 +54,7 @@ o3djs.require('o3djs.util'); o3djs.require('o3djs.math'); o3djs.require('o3djs.rendergraph'); o3djs.require('o3djs.primitives'); -o3djs.require('o3djs.effect'); +o3djs.require('o3djs.material'); o3djs.require('o3djs.fps'); // Events @@ -112,19 +112,10 @@ function initStep2(clientElements) { g_client.renderGraphRoot); // Create a material. - var myMaterial = g_pack.createObject('Material'); - - // Set the material's drawList for opaque objects. - myMaterial.drawList = g_viewInfo.performanceDrawList; - - // Create and load the effect. - var effect = g_pack.createObject('Effect'); - o3djs.effect.loadEffect(effect, 'shaders/vertex-color.shader'); - - // Apply our effect to this material and create the params the effect needs - // on the material. - myMaterial.effect = effect; - effect.createUniformParameters(myMaterial); + var myMaterial = o3djs.material.createMaterialFromFile( + g_pack, + 'shaders/vertex-color.shader', + g_viewInfo.performanceDrawList); // Draw a cube using the effect we have loaded. var myShape = o3djs.primitives.createRainbowCube(g_pack, -- cgit v1.1