001: /*
002: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024:
025: package com.sun.jsr239;
026:
027: import javax.microedition.khronos.opengles.GL11;
028: import javax.microedition.khronos.opengles.GL11Ext;
029: import javax.microedition.khronos.opengles.GL11ExtensionPack;
030:
031: import com.sun.midp.main.Configuration;
032:
033: /**
034: * A class containing constants that describe the OpenGL ES version
035: * supported by the runtime platform and the set of supported
036: * extensions. This class also contains methods that return the
037: * number of values that will be returned by various 'getters' as well
038: * as tunable implementation parameters.
039: */
040: public final class GLConfiguration {
041:
042: /**
043: * If true, each GL command will be submitted to the native OpenGL
044: * ES engine immediately.
045: */
046: public static boolean flushQueueAfterEachCommand = false;
047:
048: /**
049: * If true, the underlying VM uses a single native thread for all
050: * Java threads, false if the VM uses a 1-1 mapping of Java
051: * threads to native thread. If the VM uses some other sort of
052: * mapping, this implementation is not guaranteed to work.
053: *
054: * The value should be 'true' for Sun's CLDC implementations,
055: * and 'false' for Sun's CDC implementation.
056: */
057: public static final boolean singleThreaded = true;
058:
059: /**
060: * True if the platform requires the bytes returned by
061: * <code>Float.floatToIntBits</code> to be swapped prior to
062: * placement on the command queue.
063: */
064: public static final boolean SWAP_FLOAT_BYTES = false;
065:
066: /**
067: * True on big-endian platforms.
068: */
069: public static boolean IS_BIG_ENDIAN = false;
070:
071: /**
072: * The maximum number of commands and arguments that will be
073: * enqueued prior to submittal to the native OpenGL ES engine.
074: */
075: public static final int COMMAND_QUEUE_SIZE = 4096;
076:
077: /**
078: * True if the native OpenGL ES engine supports EGL 1.1
079: */
080: public static boolean supportsEGL11 = true;
081:
082: /**
083: * True if the native OpenGL ES engine supports OpenGL ES 1.1
084: */
085: public static boolean supportsGL11 = true;
086:
087: /**
088: * True if the native OpenGL ES engine supports
089: * the <code>OES_query_matrix</code> extension.
090: */
091: public static boolean supports_OES_query_matrix = true;
092:
093: /**
094: * True if the native OpenGL ES engine supports
095: * the <code>OES_query_matrix</code> extension.
096: */
097: public static boolean supports_OES_draw_texture = true;
098:
099: /**
100: * True if the native OpenGL ES engine supports
101: * the <code>OES_query_matrix</code> extension.
102: */
103: public static boolean supports_OES_matrix_palette = true;
104:
105: /**
106: * True if the native OpenGL ES engine supports
107: * the <code>OES_texture_cube_map</code> extension.
108: */
109: public static boolean supports_OES_texture_cube_map = false;
110:
111: /**
112: * True if the native OpenGL ES engine supports
113: * the <code>OES_texture_env_crossbar</code> extension.
114: */
115: public static boolean supports_OES_texture_env_crossbar = false;
116:
117: /**
118: * True if the native OpenGL ES engine supports
119: * the <code>OES_texture_mirrored_repeate</code> extension.
120: */
121: public static boolean supports_OES_texture_mirrored_repeat = false;
122:
123: /**
124: * True if the native OpenGL ES engine supports
125: * the <code>OES_blend_subtract</code> extension.
126: */
127: public static boolean supports_OES_blend_subtract = false;
128:
129: /**
130: * True if the native OpenGL ES engine supports
131: * the <code>OES_blend_func_separate</code> extension.
132: */
133: public static boolean supports_OES_blend_func_separate = false;
134:
135: /**
136: * True if the native OpenGL ES engine supports
137: * the <code>OES_blend_equation_separate</code> extension.
138: */
139: public static boolean supports_OES_blend_equation_separate = false;
140:
141: /**
142: * True if the native OpenGL ES engine supports
143: * the <code>OES_stencil_wrap</code> extension.
144: */
145: public static boolean supports_OES_stencil_wrap = false;
146:
147: /**
148: * True if the native OpenGL ES engine supports
149: * the <code>OES_extended_matrix_palette</code> extension.
150: */
151: public static boolean supports_OES_extended_matrix_palette = false;
152:
153: /**
154: * True if the native OpenGL ES engine supports
155: * the <code>OES_framebuffer_object</code> extension.
156: */
157: public static boolean supports_OES_framebuffer_object = false;
158:
159: /**
160: * The number of compressed texture formats, as returned by
161: * 'glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS)'
162: */
163: public static final int NUM_COMPRESSED_TEXTURE_FORMATS = 10;
164:
165: /**
166: * The value of GL_MAX_VERTEX_UNITS_OES.
167: */
168: public static final int MAX_VERTEX_UNITS = 4;
169:
170: private static boolean getBooleanProp(String p, boolean defaultVal) {
171: String propString = Configuration.getProperty(p);
172: boolean returnVal = defaultVal;
173: if (propString != null) {
174: if (propString.equals("true") || propString.equals("t")
175: || propString.equals("True")
176: || propString.equals("T") || propString.equals("1")) {
177: returnVal = true;
178: } else if (propString.equals("false")
179: || propString.equals("f")
180: || propString.equals("False")
181: || propString.equals("F") || propString.equals("0")) {
182: returnVal = false;
183: }
184: }
185: return returnVal;
186: }
187:
188: static {
189: flushQueueAfterEachCommand = getBooleanProp("jsr239.noqueue",
190: false);
191:
192: supportsEGL11 = getBooleanProp("jsr239.supportsEGL11", true);
193:
194: supportsGL11 = getBooleanProp("jsr239.supportsGL11", true);
195:
196: supports_OES_query_matrix = getBooleanProp(
197: "jsr239.supports_OES_query_matrix", true);
198:
199: supports_OES_draw_texture = getBooleanProp(
200: "jsr239.supports_OES_draw_texture", true);
201:
202: supports_OES_matrix_palette = getBooleanProp(
203: "jsr239.supports_OES_matrix_palette", true);
204:
205: supports_OES_texture_cube_map = getBooleanProp(
206: "jsr239.supports_OES_texture_cube_map", false);
207:
208: supports_OES_texture_env_crossbar = getBooleanProp(
209: "jsr239.supports_OES_texture_env_crossbar", false);
210:
211: supports_OES_texture_mirrored_repeat = getBooleanProp(
212: "jsr239.supports_OES_texture_mirrored_repeat", false);
213:
214: supports_OES_blend_subtract = getBooleanProp(
215: "jsr239.supports_OES_blend_subtract", false);
216:
217: supports_OES_blend_func_separate = getBooleanProp(
218: "jsr239.supports_OES_blend_func_separate", false);
219:
220: supports_OES_blend_equation_separate = getBooleanProp(
221: "jsr239.supports_OES_blend_equation_separate", false);
222:
223: supports_OES_stencil_wrap = getBooleanProp(
224: "jsr239.supports_OES_stencil_wrap", false);
225:
226: supports_OES_extended_matrix_palette = getBooleanProp(
227: "jsr239.supports_OES_extended_matrix_palette", false);
228:
229: supports_OES_framebuffer_object = getBooleanProp(
230: "jsr239.supports_OES_framebuffer_object", false);
231: }
232:
233: /**
234: * Returns the number of values required by the given
235: * parameter <code>pname</code> by <code>glFog*v</code>.
236: */
237: public static int glFogNumParams(int pname) {
238: return (pname == GL11.GL_FOG_COLOR) ? 4 : 1;
239: }
240:
241: /**
242: * Returns the number of values required by the given
243: * parameter <code>pname</code> by <code>glGetFixedv</code>,
244: * <code>glGetFloatv</code>, and <code>glGetIntegerv</code>.
245: */
246: public static int glGetNumParams(int pname) {
247: switch (pname) {
248: case GL11.GL_ALPHA_BITS:
249: case GL11.GL_ALPHA_TEST_FUNC:
250: case GL11.GL_ALPHA_TEST_REF:
251: case GL11.GL_BLEND_DST:
252: case GL11ExtensionPack.GL_BLEND_DST_ALPHA:
253: case GL11ExtensionPack.GL_BLEND_DST_RGB:
254: case GL11ExtensionPack.GL_BLEND_EQUATION:
255: /* synonym: GL11ExtensionPack.GL_BLEND_EQUATION_RGB */
256: case GL11ExtensionPack.GL_BLEND_EQUATION_ALPHA:
257: case GL11.GL_BLEND_SRC:
258: case GL11ExtensionPack.GL_BLEND_SRC_ALPHA:
259: case GL11ExtensionPack.GL_BLEND_SRC_RGB:
260: case GL11.GL_BLUE_BITS:
261: case GL11.GL_COLOR_ARRAY_BUFFER_BINDING:
262: case GL11.GL_COLOR_ARRAY_SIZE:
263: case GL11.GL_COLOR_ARRAY_STRIDE:
264: case GL11.GL_COLOR_ARRAY_TYPE:
265: case GL11ExtensionPack.GL_MAX_CUBE_MAP_TEXTURE_SIZE:
266: case GL11.GL_CULL_FACE:
267: case GL11.GL_DEPTH_BITS:
268: case GL11.GL_DEPTH_CLEAR_VALUE:
269: case GL11.GL_DEPTH_FUNC:
270: case GL11.GL_DEPTH_WRITEMASK:
271: case GL11.GL_FOG_DENSITY:
272: case GL11.GL_FOG_END:
273: case GL11.GL_FOG_HINT:
274: case GL11.GL_FOG_MODE:
275: case GL11.GL_FOG_START:
276: case GL11.GL_FRONT_FACE:
277: case GL11.GL_GREEN_BITS:
278: case GL11.GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
279: case GL11.GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
280: case GL11.GL_LIGHT_MODEL_TWO_SIDE:
281: case GL11.GL_LINE_SMOOTH_HINT:
282: case GL11.GL_LINE_WIDTH:
283: case GL11.GL_LOGIC_OP_MODE:
284: case GL11Ext.GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES:
285: case GL11Ext.GL_MATRIX_INDEX_ARRAY_SIZE_OES:
286: case GL11Ext.GL_MATRIX_INDEX_ARRAY_STRIDE_OES:
287: case GL11.GL_MATRIX_MODE:
288: case GL11.GL_MAX_CLIP_PLANES:
289: case GL11.GL_MAX_ELEMENTS_INDICES:
290: case GL11.GL_MAX_ELEMENTS_VERTICES:
291: case GL11.GL_MAX_LIGHTS:
292: case GL11.GL_MAX_MODELVIEW_STACK_DEPTH:
293: case GL11Ext.GL_MAX_PALETTE_MATRICES_OES:
294: case GL11.GL_MAX_PROJECTION_STACK_DEPTH:
295: case GL11.GL_MAX_TEXTURE_SIZE:
296: case GL11.GL_MAX_TEXTURE_STACK_DEPTH:
297: case GL11.GL_MAX_TEXTURE_UNITS:
298: case GL11Ext.GL_MAX_VERTEX_UNITS_OES:
299: case GL11.GL_MODELVIEW_STACK_DEPTH:
300: case GL11.GL_NORMAL_ARRAY_BUFFER_BINDING:
301: case GL11.GL_NORMAL_ARRAY_STRIDE:
302: case GL11.GL_NORMAL_ARRAY_TYPE:
303: case GL11.GL_NUM_COMPRESSED_TEXTURE_FORMATS:
304: case GL11.GL_PACK_ALIGNMENT:
305: case GL11.GL_PERSPECTIVE_CORRECTION_HINT:
306: case GL11.GL_POINT_SIZE:
307: case GL11.GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
308: case GL11.GL_POINT_SIZE_ARRAY_STRIDE_OES:
309: case GL11.GL_POINT_SIZE_ARRAY_TYPE_OES:
310: case GL11.GL_POINT_SMOOTH_HINT:
311: case GL11.GL_POLYGON_OFFSET_FACTOR:
312: case GL11.GL_POLYGON_OFFSET_UNITS:
313: case GL11.GL_PROJECTION_STACK_DEPTH:
314: case GL11.GL_RED_BITS:
315: case GL11.GL_SHADE_MODEL:
316: case GL11.GL_STENCIL_BITS:
317: case GL11.GL_STENCIL_CLEAR_VALUE:
318: case GL11.GL_STENCIL_FAIL:
319: case GL11.GL_STENCIL_FUNC:
320: case GL11.GL_STENCIL_PASS_DEPTH_FAIL:
321: case GL11.GL_STENCIL_PASS_DEPTH_PASS:
322: case GL11.GL_STENCIL_REF:
323: case GL11.GL_STENCIL_VALUE_MASK:
324: case GL11.GL_STENCIL_WRITEMASK:
325: case GL11.GL_SUBPIXEL_BITS:
326: case GL11.GL_TEXTURE_BINDING_2D:
327: case GL11.GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
328: case GL11.GL_TEXTURE_COORD_ARRAY_SIZE:
329: case GL11.GL_TEXTURE_COORD_ARRAY_STRIDE:
330: case GL11.GL_TEXTURE_COORD_ARRAY_TYPE:
331: case GL11.GL_TEXTURE_STACK_DEPTH:
332: case GL11.GL_UNPACK_ALIGNMENT:
333: case GL11.GL_VERTEX_ARRAY_BUFFER_BINDING:
334: case GL11.GL_VERTEX_ARRAY_SIZE:
335: case GL11.GL_VERTEX_ARRAY_STRIDE:
336: case GL11.GL_VERTEX_ARRAY_TYPE:
337: case GL11Ext.GL_WEIGHT_ARRAY_BUFFER_BINDING_OES:
338: case GL11Ext.GL_WEIGHT_ARRAY_SIZE_OES:
339: case GL11Ext.GL_WEIGHT_ARRAY_STRIDE_OES:
340: case GL11Ext.GL_WEIGHT_ARRAY_TYPE_OES:
341: return 1;
342:
343: case GL11.GL_ALIASED_POINT_SIZE_RANGE:
344: case GL11.GL_ALIASED_LINE_WIDTH_RANGE:
345: case GL11.GL_DEPTH_RANGE:
346: case GL11.GL_MAX_VIEWPORT_DIMS:
347: case GL11.GL_SMOOTH_LINE_WIDTH_RANGE:
348: case GL11.GL_SMOOTH_POINT_SIZE_RANGE:
349: return 2;
350:
351: case GL11.GL_COLOR_CLEAR_VALUE:
352: case GL11.GL_COLOR_WRITEMASK:
353: case GL11.GL_FOG_COLOR:
354: case GL11.GL_LIGHT_MODEL_AMBIENT:
355: case GL11.GL_SCISSOR_BOX:
356: case GL11.GL_VIEWPORT:
357: return 4;
358:
359: case GL11.GL_COMPRESSED_TEXTURE_FORMATS:
360: return NUM_COMPRESSED_TEXTURE_FORMATS;
361:
362: case GL11.GL_MODELVIEW_MATRIX:
363: case GL11.GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES:
364: case GL11.GL_PROJECTION_MATRIX:
365: case GL11.GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES:
366: case GL11.GL_TEXTURE_MATRIX:
367: case GL11.GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES:
368: return 16;
369:
370: default:
371: System.out
372: .println("GLConfiguration: glGetNumParams called "
373: + "with pname=" + pname);
374: return 0;
375: }
376: }
377:
378: /**
379: * Returns the number of values required by the given parameter
380: * <code>pname</code> by <code>glGetBufferParameteriv</code>.
381: */
382: public static int glGetBufferParametervNumParams(int pname) {
383: return 1;
384: }
385:
386: /**
387: * Returns the number of values required by the given parameter
388: * <code>pname</code> by <code>glLight*v</code>.
389: */
390: public static int glLightNumParams(int pname) {
391: switch (pname) {
392: case GL11.GL_SPOT_EXPONENT:
393: case GL11.GL_SPOT_CUTOFF:
394: case GL11.GL_CONSTANT_ATTENUATION:
395: case GL11.GL_LINEAR_ATTENUATION:
396: case GL11.GL_QUADRATIC_ATTENUATION:
397: return 1;
398:
399: case GL11.GL_SPOT_DIRECTION:
400: return 3;
401:
402: case GL11.GL_POSITION:
403: case GL11.GL_AMBIENT:
404: case GL11.GL_DIFFUSE:
405: case GL11.GL_SPECULAR:
406: case GL11.GL_EMISSION:
407: return 4;
408:
409: default:
410: System.out
411: .println("GLConfiguration: glLightNumParams called "
412: + "with pname=" + pname);
413: return 0;
414: }
415: }
416:
417: /**
418: * Returns the number of values required by the given parameter
419: * <code>pname</code> by <code>glLightModel*v</code>.
420: */
421: public static int glLightModelNumParams(int pname) {
422: switch (pname) {
423: case GL11.GL_LIGHT_MODEL_AMBIENT:
424: return 4;
425: case GL11.GL_LIGHT_MODEL_TWO_SIDE:
426: return 1;
427: default:
428: System.out
429: .println("GLConfiguration: glLightModelNumParams "
430: + "called with pname=" + pname);
431: return 0;
432: }
433: }
434:
435: /**
436: * Returns the number of values required by the given parameter
437: * <code>pname</code> by <code>glMaterial*v</code>.
438: */
439: public static int glMaterialNumParams(int pname) {
440: switch (pname) {
441: case GL11.GL_AMBIENT:
442: case GL11.GL_DIFFUSE:
443: case GL11.GL_SPECULAR:
444: case GL11.GL_EMISSION:
445: return 4;
446:
447: case GL11.GL_SHININESS:
448: return 1;
449:
450: default:
451: System.out.println("GLConfiguration: glMaterialNumParams "
452: + "called with pname=" + pname);
453: return 0;
454: }
455: }
456:
457: /**
458: * Returns the number of values required by the given parameter
459: * <code>pname</code> by <code>glPointParameter*v</code>.
460: */
461: public static int glPointParameterNumParams(int pname) {
462: return (pname == GL11.GL_POINT_DISTANCE_ATTENUATION) ? 3 : 1;
463: }
464:
465: /**
466: * Returns the number of values required by the given parameter
467: * <code>pname</code> by <code>glTexEnv*v</code>.
468: */
469: public static int glTexEnvNumParams(int pname) {
470: switch (pname) {
471: case GL11.GL_TEXTURE_ENV_MODE:
472: case GL11.GL_COMBINE_RGB:
473: case GL11.GL_COMBINE_ALPHA:
474: case GL11.GL_COORD_REPLACE_OES:
475: return 1;
476: case GL11.GL_TEXTURE_ENV_COLOR:
477: return 4;
478: default:
479: System.out
480: .println("GLConfiguration: glTexEnvNumParams called "
481: + "with pname=" + pname);
482: return 0;
483: }
484: }
485:
486: /**
487: * Returns the number of values required by the given parameter
488: * <code>pname</code> by <code>glTexGen*v</code>.
489: */
490: public static int glTexGenNumParams(int pname) {
491: return 1;
492: }
493:
494: /**
495: * Returns the number of values required by the given parameter
496: * <code>pname</code> by <code>glTexParameter*v</code>.
497: */
498: public static int glTexParameterNumParams(int pname) {
499: switch (pname) {
500: case GL11.GL_TEXTURE_MIN_FILTER:
501: case GL11.GL_TEXTURE_MAG_FILTER:
502: case GL11.GL_TEXTURE_WRAP_S:
503: case GL11.GL_TEXTURE_WRAP_T:
504: case GL11.GL_GENERATE_MIPMAP:
505: return 1;
506: case GL11Ext.GL_TEXTURE_CROP_RECT_OES:
507: return 4;
508: default:
509: System.out
510: .println("GLConfiguration: glTexParameterNumParams "
511: + "called with pname=" + pname);
512: return 0;
513: }
514: }
515:
516: /**
517: * Returns the number of values required by the given parameter
518: * <code>pname</code> by <code>glRenderbufferParameterivOES</code>
519: * and <code>glGetRenderbufferParameterivOES</code>.
520: */
521: public static int glRenderbufferParameterNumParams(int pname) {
522: return 1;
523: }
524:
525: /**
526: * Returns the number of values required by the given parameter
527: * <code>pname</code> by
528: * <code>glFramebufferAttachmentParameterivOES</code> and
529: * <code>glGetFramebufferAttachmentParameterivOES</code>.
530: */
531: public static int glFramebufferAttachmentParameterNumParams(
532: int pname) {
533: return 1;
534: }
535:
536: /**
537: * Returns the number of bytes associated with a given GL data type.
538: */
539: public static int sizeOfType(int type) {
540: switch (type) {
541: case GL11.GL_BYTE:
542: case GL11.GL_UNSIGNED_BYTE:
543: return 1;
544:
545: case GL11.GL_SHORT:
546: case GL11.GL_UNSIGNED_SHORT_4_4_4_4:
547: case GL11.GL_UNSIGNED_SHORT_5_5_5_1:
548: case GL11.GL_UNSIGNED_SHORT_5_6_5:
549: return 2;
550:
551: case GL11.GL_FIXED:
552: case GL11.GL_FLOAT:
553: return 4;
554: }
555:
556: throw new IllegalArgumentException("Unknown type: " + type);
557: }
558:
559: /**
560: * Returns the number of channels associated with a given
561: * GL pixel format.
562: */
563: public static int formatChannels(int format) {
564: switch (format) {
565: case GL11.GL_LUMINANCE:
566: case GL11.GL_ALPHA:
567: return 1;
568:
569: case GL11.GL_LUMINANCE_ALPHA:
570: return 2;
571:
572: case GL11.GL_RGB:
573: return 3;
574:
575: case GL11.GL_RGBA:
576: return 4;
577: }
578:
579: throw new IllegalArgumentException("Unknown format: " + format);
580: }
581: }
|