Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Side by Side Diff: samples/o3d-webgl/client.js

Issue 2803007: o3d-webgl: convolution shader and error texture. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/o3d-webgl/base.js ('k') | samples/o3d-webgl/effect.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010, Google Inc. 2 * Copyright 2010, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 gl.hack_canvas = canvas; 645 gl.hack_canvas = canvas;
646 this.gl = gl; 646 this.gl = gl;
647 this.root.gl = gl; 647 this.root.gl = gl;
648 this.renderGraphRoot.gl = gl; 648 this.renderGraphRoot.gl = gl;
649 649
650 gl.client = this; 650 gl.client = this;
651 gl.displayInfo = {width: canvas.width, 651 gl.displayInfo = {width: canvas.width,
652 height: canvas.height}; 652 height: canvas.height};
653 o3d.State.createDefaultState_(gl).push_(); 653 o3d.State.createDefaultState_(gl).push_();
654 654
655 // Create the default error texture.
656 var defaultTexture = new o3d.Texture2D();
657 defaultTexture.gl = this.gl;
658 defaultTexture.init_(8, 8, o3d.Texture.ARGB8, 1, false);
659 var r = [1, 0, 0, 1];
660 var Y = [1, 1, 0, 1];
661 var error = [r, r, r, r, r, r, r, r,
662 r, r, Y, Y, Y, Y, r, r,
663 r, Y, r, r, r, Y, Y, r,
664 r, Y, r, r, Y, r, Y, r,
665 r, Y, r, Y, r, r, Y, r,
666 r, Y, Y, r, r, r, Y, r,
667 r, r, Y, Y, Y, Y, r, r,
668 r, r, r, r, r, r, r, r];
669 var pixels = [];
670 for (var i = 0; i < error.length; i++) {
671 for (var j = 0; j < 4; j++) {
672 pixels[i * 4 + j] = error[i][j];
673 }
674 }
675 defaultTexture.set(0, pixels);
676 defaultTexture.name = 'DefaultTexture';
677 this.fallback_error_texture_ = defaultTexture;
678 this.error_texture_ = defaultTexture;
679
655 return true; 680 return true;
656 }; 681 };
657 682
658 683
659 /** 684 /**
660 * Sets the per frame render callback. 685 * Sets the per frame render callback.
661 * 686 *
662 * Note: The callback will not be called recursively. When your callback is 687 * Note: The callback will not be called recursively. When your callback is
663 * called if you somehow manage to cause the client to render more frames 688 * called if you somehow manage to cause the client to render more frames
664 * before you've returned from the callback you will not be called for those 689 * before you've returned from the callback you will not be called for those
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 * you get any errors using Client.setErrorCallback or Client.lastError. 935 * you get any errors using Client.setErrorCallback or Client.lastError.
911 * 936 *
912 * var t = g_pack.createTexture2D('', 1, 1, g_o3d.Texture.XRGB8, 1); 937 * var t = g_pack.createTexture2D('', 1, 1, g_o3d.Texture.XRGB8, 1);
913 * t.set(0, [0, 0, 0]); 938 * t.set(0, [0, 0, 0]);
914 * g_client.setErrorTexture(t); 939 * g_client.setErrorTexture(t);
915 * 940 *
916 * @param {o3d.Texture} texture texture to use for missing textures or null. 941 * @param {o3d.Texture} texture texture to use for missing textures or null.
917 */ 942 */
918 o3d.Client.prototype.setErrorTexture = 943 o3d.Client.prototype.setErrorTexture =
919 function(texture) { 944 function(texture) {
920 o3d.notImplemented(); 945 this.error_texture_ = texture;
921 }; 946 };
922 947
923 948
924 /** 949 /**
925 * Sets a callback for when the client ticks. The client processes some things 950 * Sets a callback for when the client ticks. The client processes some things
926 * like animation timers at up to 100hz. This callback will get called before 951 * like animation timers at up to 100hz. This callback will get called before
927 * each of those process ticks. 952 * each of those process ticks.
928 * 953 *
929 * NOTE: The client takes ownership of the TickCallback you 954 * NOTE: The client takes ownership of the TickCallback you
930 * pass in. It will be deleted if you call SetTickCallback a 955 * pass in. It will be deleted if you call SetTickCallback a
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 * an alert everytime the client tries to render which is every time you close 996 * an alert everytime the client tries to render which is every time you close
972 * the current alert which means you'll be in an infinite loop of alerts. 997 * the current alert which means you'll be in an infinite loop of alerts.
973 * 998 *
974 * @param {o3d.ErrorCallback} error_callback ErrorCallback to call when the 999 * @param {o3d.ErrorCallback} error_callback ErrorCallback to call when the
975 * Client gets an error. 1000 * Client gets an error.
976 */ 1001 */
977 o3d.Client.prototype.setErrorCallback = 1002 o3d.Client.prototype.setErrorCallback =
978 function(error_callback) { 1003 function(error_callback) {
979 // Other code expects to not see a null error callback. 1004 // Other code expects to not see a null error callback.
980 if (error_callback) { 1005 if (error_callback) {
981 this.error_callback = error_callback; 1006 this.error_callback = this.wrapErrorCallback_(error_callback);
982 } else { 1007 } else {
983 this.error_callback = function(string) {}; 1008 this.error_callback = function(string) {
1009 this.last_error_ = string;
1010 };
984 } 1011 }
985 }; 1012 };
986 1013
987 1014
988 /** 1015 /**
1016 * Wraps a callback function, saving the error string so that the
1017 * lastError variable can access it.
1018 *
1019 * @param {function} error_callback User-defined error callback.
1020 * @return {function} Wrapped error callback.
1021 * @private
1022 */
1023 o3d.Client.prototype.wrapErrorCallback_ = function(error_callback) {
1024 return function(string) {
1025 this.last_error_ = string;
1026 error_callback(string);
1027 }
1028 }
1029
1030
1031 /**
989 * Clears the Error callback 1032 * Clears the Error callback
990 * 1033 *
991 * NOTE: The client takes ownership of the ErrorCallback you 1034 * NOTE: The client takes ownership of the ErrorCallback you
992 * pass in. It will be deleted if you call SetErrorCallback a second 1035 * pass in. It will be deleted if you call SetErrorCallback a second
993 * time or if you call ClearErrorCallback. 1036 * time or if you call ClearErrorCallback.
994 */ 1037 */
995 o3d.Client.prototype.clearErrorCallback = function() { 1038 o3d.Client.prototype.clearErrorCallback = function() {
996 this.setErrorCallback(null); 1039 this.setErrorCallback(null);
997 }; 1040 };
998 1041
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 * Returns the status of initializing the renderer so we can display the 1138 * Returns the status of initializing the renderer so we can display the
1096 * appropriate message. We require a certain minimum set of graphics 1139 * appropriate message. We require a certain minimum set of graphics
1097 * capabilities. If the user's computer does not have his minimum 1140 * capabilities. If the user's computer does not have his minimum
1098 * set this will be GPU_NOT_UP_TO_SPEC. If the user is out of graphics 1141 * set this will be GPU_NOT_UP_TO_SPEC. If the user is out of graphics
1099 * resources this will be OUT_OF_RESOURCES. If some other error happened this 1142 * resources this will be OUT_OF_RESOURCES. If some other error happened this
1100 * will be INITIALIZATION_ERROR. Otherwise it will be SUCCESS. 1143 * will be INITIALIZATION_ERROR. Otherwise it will be SUCCESS.
1101 */ 1144 */
1102 o3d.Client.prototype.renderer_init_status = 0; 1145 o3d.Client.prototype.renderer_init_status = 0;
1103 1146
1104 1147
1105
1106 /** 1148 /**
1107 * Gets / Sets the cursor's shape. 1149 * Gets / Sets the cursor's shape.
1108 * 1150 *
1109 * @type {o3d.Cursor} 1151 * @type {o3d.Cursor}
1110 */ 1152 */
1111 o3d.Client.prototype.cursor = null; 1153 o3d.Client.prototype.cursor = null;
1112 1154
1113 1155
1114 /** 1156 /**
1157 * The current error texture.
1158 *
1159 * @type {o3d.Texture}
1160 * @private
1161 */
1162 o3d.Client.prototype.error_texture_ = null;
1163
1164
1165 /**
1166 * The fallback error texture. Should only be initialized once per client and
1167 * is read-only.
1168 *
1169 * @type {!o3d.Texture}
1170 * @private
1171 */
1172 o3d.Client.prototype.fallback_error_texture_ = null;
1173
1174
1175 /**
1115 * The last error reported by the plugin. 1176 * The last error reported by the plugin.
1116 * 1177 *
1117 * @type {string} 1178 * @type {string}
1179 * @private
1118 */ 1180 */
1119 o3d.Client.prototype.last_error_ = ''; 1181 o3d.Client.prototype.last_error_ = '';
1182 o3d.Client.prototype.__defineGetter__('lastError',
1183 function() {
1184 return this.last_error_;
1185 }
1186 );
1120 1187
1188 /**
1189 * Returns true if missing textures, samplers or ParamSamplers should be
1190 * reported by calling the error callback. We assume that if the user
1191 * explicitly sets the error texture to null, then they want such errors to
1192 * trigger the error callback.
1193 *
1194 * @return {boolean}
1195 * @private
1196 */
1197 o3d.Client.prototype.reportErrors_ = function() {
1198 return (this.error_texture_ == null);
1199 }
1121 1200
1122 1201
1123 /** 1202 /**
1124 * All the objects managed by this client. 1203 * All the objects managed by this client.
1125 * 1204 *
1126 * Each access to this field gets the entire list so it is best to get it 1205 * Each access to this field gets the entire list so it is best to get it
1127 * just once. For example: 1206 * just once. For example:
1128 * 1207 *
1129 * var objects = client.objects; 1208 * var objects = client.objects;
1130 * for (var i = 0; i < objects.length; i++) { 1209 * for (var i = 0; i < objects.length; i++) {
1131 * var object = objects[i]; 1210 * var object = objects[i];
1132 * } 1211 * }
1133 * 1212 *
1134 * 1213 *
1135 * Note that modifications to this array [e.g. push()] will not affect 1214 * Note that modifications to this array [e.g. push()] will not affect
1136 * the underlying Client, while modifications to the array's members 1215 * the underlying Client, while modifications to the array's members
1137 * will affect them. 1216 * will affect them.
1138 * 1217 *
1139 * @type {!Array.<!o3d.ObjectBase>} 1218 * @type {!Array.<!o3d.ObjectBase>}
1140 */ 1219 */
1141 o3d.Client.prototype.objects = []; 1220 o3d.Client.prototype.objects = [];
1142 1221
1143 1222
1144 1223
1145 /** 1224 /**
1146 * Clears the error returned in lastError. 1225 * Clears the error returned in lastError.
1147 */ 1226 */
1148 o3d.Client.prototype.clearLastError = function () { 1227 o3d.Client.prototype.clearLastError = function () {
1149 o3d.notImplemented(); 1228 this.last_error_ = '';
1150 }; 1229 };
1151 1230
1152 1231
1153 1232
1154 /** 1233 /**
1155 * Resets the profiling information. 1234 * Resets the profiling information.
1156 */ 1235 */
1157 o3d.Client.prototype.profileReset = function() { 1236 o3d.Client.prototype.profileReset = function() {
1158 o3d.notImplemented(); 1237 o3d.notImplemented();
1159 }; 1238 };
(...skipping 23 matching lines...) Expand all
1183 * Gets info about the client. 1262 * Gets info about the client.
1184 */ 1263 */
1185 o3d.Client.prototype.clientInfo = null; 1264 o3d.Client.prototype.clientInfo = null;
1186 1265
1187 1266
1188 /** 1267 /**
1189 * The canvas associated with this client. 1268 * The canvas associated with this client.
1190 * @type {Element} 1269 * @type {Element}
1191 */ 1270 */
1192 o3d.Client.prototype.canvas = null; 1271 o3d.Client.prototype.canvas = null;
1193
1194
OLDNEW
« no previous file with comments | « samples/o3d-webgl/base.js ('k') | samples/o3d-webgl/effect.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698