001: /*
002: * $RCSfile: ShaderError.java,v $
003: *
004: * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.5 $
028: * $Date: 2008/02/28 20:17:30 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.io.PrintStream;
035:
036: /**
037: * ShaderError is a container object that holds the details of
038: * a runtime error that occurs while compiling or executing a
039: * programmable shader.
040: *
041: * @since Java 3D 1.4
042: */
043: public class ShaderError extends Object {
044: private int errorCode = NO_ERROR;
045: private String errorMessage = null;
046: private String detailMessage = null;
047: private Canvas3D canvas = null;
048: private Shape3D shape = null;
049: private Geometry geometry = null;
050: private ShaderAppearance shaderApp = null;
051: private ShaderProgram shaderProgram = null;
052: private Shader shader = null;
053: private ShaderAttributeSet shaderAttributeSet = null;
054: private ShaderAttribute shaderAttribute = null;
055:
056: /**
057: * Indicates that no error occurred.
058: */
059: public static final int NO_ERROR = 0;
060:
061: /**
062: * Indicates that an error occurred while compiling a shader.
063: */
064: public static final int COMPILE_ERROR = 1;
065:
066: /**
067: * Indicates that an error occurred while linking a shader.
068: */
069: public static final int LINK_ERROR = 2;
070:
071: /**
072: * Indicates a error in looking up a vertex attribute
073: * name within a given shader program.
074: */
075: public static final int VERTEX_ATTRIBUTE_LOOKUP_ERROR = 3;
076:
077: /**
078: * Indicates a error in looking up the location of a uniform
079: * shader attribute name within a given shader program.
080: */
081: public static final int SHADER_ATTRIBUTE_LOOKUP_ERROR = 4;
082:
083: /**
084: * Indicates a error caused by a ShaderAttribute whose name does not
085: * appear in the list of shader attribute names in the corresponding
086: * ShaderProgram object.
087: */
088: public static final int SHADER_ATTRIBUTE_NAME_NOT_SET_ERROR = 5;
089:
090: /**
091: * Indicates a error in the type of the attribute versus what the shader
092: * program was expecting.
093: */
094: public static final int SHADER_ATTRIBUTE_TYPE_ERROR = 6;
095:
096: /**
097: * Indicates that the specified shading language is not supported
098: * on the screen display device.
099: */
100: public static final int UNSUPPORTED_LANGUAGE_ERROR = 7;
101:
102: /**
103: * Constructs a new ShaderError object indicating no error. The
104: * error code is set to <code>NO_ERROR</code>. All other fields
105: * are initialized to null, including the error message.
106: */
107: public ShaderError() {
108: }
109:
110: /**
111: * Constructs a new ShaderError object with the given error code
112: * and message. All other fields are initialized to null.
113: *
114: * @param errorCode the error code for this shader error.
115: *
116: * @param errorMessage a short error message describing this
117: * shader error.
118: */
119: public ShaderError(int errorCode, String errorMessage) {
120: this .errorCode = errorCode;
121: this .errorMessage = errorMessage;
122: }
123:
124: /**
125: * Prints a verbose error report to System.err. This verbose
126: * output includes the error code, error message, detail message,
127: * and all relevant Java 3D objects.
128: */
129: public void printVerbose() {
130: printVerbose(System.err);
131: }
132:
133: /**
134: * Prints a verbose error report to the specified PrintStream.
135: * This verbose output includes the error code, error message,
136: * detail message, and all relevant Java 3D objects.
137: *
138: * @param printStream the print stream on which to print the error
139: * report.
140: */
141: public void printVerbose(PrintStream printStream) {
142: printStream.println(this );
143: if (canvas != null) {
144: printStream.println("canvas = " + canvas);
145: }
146: if (shape != null) {
147: printStream.println("shape = " + shape);
148: }
149: if (geometry != null) {
150: printStream.println("geometry = " + geometry);
151: }
152: if (shaderApp != null) {
153: printStream.println("shaderApp = " + shaderApp);
154: }
155: if (shaderProgram != null) {
156: printStream.println("shaderProgram = " + shaderProgram);
157: }
158: if (shader != null) {
159: printStream.println("shader = " + shader);
160: }
161: if (shaderAttributeSet != null) {
162: printStream.println("shaderAttributeSet = "
163: + shaderAttributeSet);
164: }
165: if (shaderAttribute != null) {
166: printStream.println("shaderAttribute = " + shaderAttribute);
167: }
168:
169: if (detailMessage != null) {
170: printStream.println();
171: printStream.println("Detail Message");
172: printStream.println("--------------");
173: printStream.println(detailMessage);
174: }
175: }
176:
177: /**
178: * Sets the error code for this shader error. This represents the
179: * type of error that occurred.
180: *
181: * @param errorCode the error code for this shader error.
182: */
183: public void setErrorCode(int errorCode) {
184: this .errorCode = errorCode;
185: }
186:
187: /**
188: * Returns the error code for this shader error.
189: *
190: * @return the error code.
191: */
192: public int getErrorCode() {
193: return errorCode;
194: }
195:
196: /**
197: * Sets the error message for this shader error. This is a short
198: * message describing the error, and is included as part of
199: * toString().
200: *
201: * @param errorMessage a short error message describing this
202: * shader error.
203: */
204: public void setErrorMessage(String errorMessage) {
205: this .errorMessage = errorMessage;
206: }
207:
208: /**
209: * Returns the error message for this shader error.
210: *
211: * @return a short error message describing this shader error.
212: */
213: public String getErrorMessage() {
214: return errorMessage;
215: }
216:
217: /**
218: * Sets the detail message for this shader error. This is a
219: * detailed error message, typically produced by the shader
220: * compiler, and is not included as part of toString().
221: *
222: * @param detailMessage a detailed message describing this shader
223: * error in more detail.
224: */
225: public void setDetailMessage(String detailMessage) {
226: this .detailMessage = detailMessage;
227: }
228:
229: /**
230: * Returns the detail message for this shader error.
231: *
232: * @return the detail message for this shader error.
233: */
234: public String getDetailMessage() {
235: return detailMessage;
236: }
237:
238: /**
239: * Sets the canvas associated with this shader error.
240: *
241: * @param canvas the canvas associated with this shader error.
242: */
243: public void setCanvas3D(Canvas3D canvas) {
244: this .canvas = canvas;
245: }
246:
247: /**
248: * Returns the canvas associated with this shader error.
249: *
250: * @return the canvas associated with this shader error.
251: */
252: public Canvas3D getCanvas3D() {
253: return this .canvas;
254: }
255:
256: /**
257: * Sets the shape node associated with this shader error.
258: *
259: * @param shape the shape node associated with this shader error.
260: */
261: public void setShape3D(Shape3D shape) {
262: this .shape = shape;
263: }
264:
265: /**
266: * Returns the shape node associated with this shader error.
267: *
268: * @return the shape node associated with this shader error.
269: */
270: public Shape3D getShape3D() {
271: return this .shape;
272: }
273:
274: /**
275: * Sets the geometry associated with this shader error.
276: *
277: * @param geometry the geometry associated with this shader error.
278: */
279: public void setGeometry(Geometry geometry) {
280: this .geometry = geometry;
281: }
282:
283: /**
284: * Returns the geometry associated with this shader error.
285: *
286: * @return the geometry associated with this shader error.
287: */
288: public Geometry getGeometry() {
289: return this .geometry;
290: }
291:
292: /**
293: * Sets the shader appearance associated with this shader error.
294: *
295: * @param shaderApp the shader appearance associated with this shader error.
296: */
297: public void setShaderAppearance(ShaderAppearance shaderApp) {
298: this .shaderApp = shaderApp;
299: }
300:
301: /**
302: * Returns the shader appearance associated with this shader error.
303: *
304: * @return the shader appearance associated with this shader error.
305: */
306: public ShaderAppearance getShaderAppearance() {
307: return this .shaderApp;
308: }
309:
310: /**
311: * Sets the shader program associated with this shader error.
312: *
313: * @param shaderProgram the shader program associated with this shader error.
314: */
315: public void setShaderProgram(ShaderProgram shaderProgram) {
316: this .shaderProgram = shaderProgram;
317: }
318:
319: /**
320: * Returns the shader program associated with this shader error.
321: *
322: * @return the shader program associated with this shader error.
323: */
324: public ShaderProgram getShaderProgram() {
325: return this .shaderProgram;
326: }
327:
328: /**
329: * Sets the shader object associated with this shader error.
330: *
331: * @param shader the shader object associated with this shader error.
332: */
333: public void setShader(Shader shader) {
334: this .shader = shader;
335: }
336:
337: /**
338: * Returns the shader object associated with this shader error.
339: *
340: * @return the shader object associated with this shader error.
341: */
342: public Shader getShader() {
343: return this .shader;
344: }
345:
346: /**
347: * Sets the shader attribute set associated with this shader error.
348: *
349: * @param shaderAttributeSet the shader attribute set associated with this shader error.
350: */
351: public void setShaderAttributeSet(
352: ShaderAttributeSet shaderAttributeSet) {
353: this .shaderAttributeSet = shaderAttributeSet;
354: }
355:
356: /**
357: * Returns the shader attribute set associated with this shader error.
358: *
359: * @return the shader attribute set associated with this shader error.
360: */
361: public ShaderAttributeSet getShaderAttributeSet() {
362: return this .shaderAttributeSet;
363: }
364:
365: /**
366: * Sets the shader attribute associated with this shader error.
367: *
368: * @param shaderAttribute the shader attribute associated with this shader error.
369: */
370: public void setShaderAttribute(ShaderAttribute shaderAttribute) {
371: this .shaderAttribute = shaderAttribute;
372: }
373:
374: /**
375: * Returns the shader attribute associated with this shader error.
376: *
377: * @return the shader attribute associated with this shader error.
378: */
379: public ShaderAttribute getShaderAttribute() {
380: return this .shaderAttribute;
381: }
382:
383: /**
384: * Returns a short string that describes this shader error. The
385: * string is composed of the textual description of the errorCode,
386: * a ": ", and the errorMessage field. If the errorMessage is
387: * null then the ": " and the errorMessage are omitted.
388: *
389: * @return a string representation of this shader error.
390: */
391: public String toString() {
392: // Concatenate string representation of error code with error message
393: String errorCodeStr;
394: switch (errorCode) {
395: case NO_ERROR:
396: errorCodeStr = "NO_ERROR";
397: break;
398: case COMPILE_ERROR:
399: errorCodeStr = "COMPILE_ERROR";
400: break;
401: case LINK_ERROR:
402: errorCodeStr = "LINK_ERROR";
403: break;
404: case VERTEX_ATTRIBUTE_LOOKUP_ERROR:
405: errorCodeStr = "VERTEX_ATTRIBUTE_LOOKUP_ERROR";
406: break;
407: case SHADER_ATTRIBUTE_LOOKUP_ERROR:
408: errorCodeStr = "SHADER_ATTRIBUTE_LOOKUP_ERROR";
409: break;
410: case SHADER_ATTRIBUTE_NAME_NOT_SET_ERROR:
411: errorCodeStr = "SHADER_ATTRIBUTE_NAME_NOT_SET_ERROR";
412: break;
413: case SHADER_ATTRIBUTE_TYPE_ERROR:
414: errorCodeStr = "SHADER_ATTRIBUTE_TYPE_ERROR";
415: break;
416: case UNSUPPORTED_LANGUAGE_ERROR:
417: errorCodeStr = "UNSUPPORTED_LANGUAGE_ERROR";
418: break;
419: default:
420: errorCodeStr = "UNKNOWN ERROR CODE (" + errorCode + ")";
421: }
422:
423: if (errorMessage == null) {
424: return errorCodeStr;
425: }
426:
427: return errorCodeStr + ": " + errorMessage;
428: }
429: }
|