GLLogWrapper.java revision 981ccfbbfd737e2bdf0cedec0089975f91fd4e0a
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.opengl;
18
19import java.io.IOException;
20import java.io.Writer;
21import java.nio.Buffer;
22import java.nio.ByteBuffer;
23import java.nio.ByteOrder;
24import java.nio.CharBuffer;
25import java.nio.DoubleBuffer;
26import java.nio.FloatBuffer;
27import java.nio.IntBuffer;
28import java.nio.LongBuffer;
29import java.nio.ShortBuffer;
30import java.util.Arrays;
31
32import javax.microedition.khronos.opengles.GL;
33
34/**
35 * A wrapper that logs all GL calls (and results) in human-readable form.
36 *
37 */
38class GLLogWrapper extends GLWrapperBase {
39    private static final int FORMAT_INT = 0;
40    private static final int FORMAT_FLOAT = 1;
41    private static final int FORMAT_FIXED = 2;
42
43    public GLLogWrapper(GL gl, Writer log, boolean logArgumentNames) {
44        super(gl);
45        mLog = log;
46        mLogArgumentNames = logArgumentNames;
47    }
48
49    private void checkError() {
50        int glError;
51        if ((glError = mgl.glGetError()) != 0) {
52            String errorMessage = "glError: " + Integer.toString(glError);
53            logLine(errorMessage);
54        }
55    }
56
57    private void logLine(String message) {
58        log(message + '\n');
59    }
60
61    private void log(String message) {
62        try {
63            mLog.write(message);
64        } catch (IOException e) {
65            // Ignore exception, keep on trying
66        }
67    }
68
69    private void begin(String name) {
70        log(name + '(');
71        mArgCount = 0;
72    }
73
74    private void arg(String name, String value) {
75        if (mArgCount++ > 0) {
76            log(", ");
77        }
78        if (mLogArgumentNames) {
79            log(name + "=");
80        }
81        log(value);
82    }
83
84    private void end() {
85        log(");\n");
86        flush();
87    }
88
89    private void flush() {
90        try {
91            mLog.flush();
92        } catch (IOException e) {
93            mLog = null;
94        }
95    }
96
97    private void arg(String name, boolean value) {
98        arg(name, Boolean.toString(value));
99    }
100
101    private void arg(String name, int value) {
102        arg(name, Integer.toString(value));
103    }
104
105    private void arg(String name, float value) {
106        arg(name, Float.toString(value));
107    }
108
109    private void returns(String result) {
110        log(") returns " + result + ";\n");
111        flush();
112    }
113
114    private void returns(int result) {
115        returns(Integer.toString(result));
116    }
117
118    private void arg(String name, int n, int[] arr, int offset) {
119        arg(name, toString(n, FORMAT_INT, arr, offset));
120    }
121
122    private void arg(String name, int n, short[] arr, int offset) {
123        arg(name, toString(n, arr, offset));
124    }
125
126    private void arg(String name, int n, float[] arr, int offset) {
127        arg(name, toString(n, arr, offset));
128    }
129
130    private void formattedAppend(StringBuilder buf, int value, int format) {
131        switch (format) {
132        case FORMAT_INT:
133            buf.append(value);
134            break;
135        case FORMAT_FLOAT:
136            buf.append(Float.intBitsToFloat(value));
137            break;
138        case FORMAT_FIXED:
139            buf.append(value / 65536.0f);
140            break;
141        }
142    }
143
144    private String toString(int n, int format, int[] arr, int offset) {
145        StringBuilder buf = new StringBuilder();
146        buf.append("{\n");
147        int arrLen = arr.length;
148        for (int i = 0; i < n; i++) {
149            int index = offset + i;
150            buf.append(" [" + index + "] = ");
151            if (index < 0 || index >= arrLen) {
152                buf.append("out of bounds");
153            } else {
154                formattedAppend(buf, arr[index], format);
155            }
156            buf.append('\n');
157        }
158        buf.append("}");
159        return buf.toString();
160    }
161
162    private String toString(int n, short[] arr, int offset) {
163        StringBuilder buf = new StringBuilder();
164        buf.append("{\n");
165        int arrLen = arr.length;
166        for (int i = 0; i < n; i++) {
167            int index = offset + i;
168            buf.append(" [" + index + "] = ");
169            if (index < 0 || index >= arrLen) {
170                buf.append("out of bounds");
171            } else {
172                buf.append(arr[index]);
173            }
174            buf.append('\n');
175        }
176        buf.append("}");
177        return buf.toString();
178    }
179
180    private String toString(int n, float[] arr, int offset) {
181        StringBuilder buf = new StringBuilder();
182        buf.append("{\n");
183        int arrLen = arr.length;
184        for (int i = 0; i < n; i++) {
185            int index = offset + i;
186            buf.append("[" + index + "] = ");
187            if (index < 0 || index >= arrLen) {
188                buf.append("out of bounds");
189            } else {
190                buf.append(arr[index]);
191            }
192            buf.append('\n');
193        }
194        buf.append("}");
195        return buf.toString();
196    }
197
198    private String toString(int n, FloatBuffer buf) {
199        StringBuilder builder = new StringBuilder();
200        builder.append("{\n");
201        for (int i = 0; i < n; i++) {
202            builder.append(" [" + i + "] = " + buf.get(i) + '\n');
203        }
204        builder.append("}");
205        return builder.toString();
206    }
207
208    private String toString(int n, int format, IntBuffer buf) {
209        StringBuilder builder = new StringBuilder();
210        builder.append("{\n");
211        for (int i = 0; i < n; i++) {
212            builder.append(" [" + i + "] = ");
213            formattedAppend(builder, buf.get(i), format);
214            builder.append('\n');
215        }
216        builder.append("}");
217        return builder.toString();
218    }
219
220    private String toString(int n, ShortBuffer buf) {
221        StringBuilder builder = new StringBuilder();
222        builder.append("{\n");
223        for (int i = 0; i < n; i++) {
224            builder.append(" [" + i + "] = " + buf.get(i) + '\n');
225        }
226        builder.append("}");
227        return builder.toString();
228    }
229
230    private void arg(String name, int n, FloatBuffer buf) {
231        arg(name, toString(n, buf));
232    }
233
234    private void arg(String name, int n, IntBuffer buf) {
235        arg(name, toString(n, FORMAT_INT, buf));
236    }
237
238    private void arg(String name, int n, ShortBuffer buf) {
239        arg(name, toString(n, buf));
240    }
241
242    private void argPointer(int size, int type, int stride, Buffer pointer) {
243        arg("size", size);
244        arg("type", getPointerTypeName(type));
245        arg("stride", stride);
246        arg("pointer", pointer.toString());
247    }
248
249    private static String getHex(int value) {
250        return "0x" + Integer.toHexString(value);
251    }
252
253    public static String getErrorString(int error) {
254        switch (error) {
255        case GL_NO_ERROR:
256            return "GL_NO_ERROR";
257        case GL_INVALID_ENUM:
258            return "GL_INVALID_ENUM";
259        case GL_INVALID_VALUE:
260            return "GL_INVALID_VALUE";
261        case GL_INVALID_OPERATION:
262            return "GL_INVALID_OPERATION";
263        case GL_STACK_OVERFLOW:
264            return "GL_STACK_OVERFLOW";
265        case GL_STACK_UNDERFLOW:
266            return "GL_STACK_UNDERFLOW";
267        case GL_OUT_OF_MEMORY:
268            return "GL_OUT_OF_MEMORY";
269        default:
270            return getHex(error);
271        }
272    }
273
274    private String getClearBufferMask(int mask) {
275        StringBuilder b = new StringBuilder();
276        if ((mask & GL_DEPTH_BUFFER_BIT) != 0) {
277            b.append("GL_DEPTH_BUFFER_BIT");
278            mask &= ~GL_DEPTH_BUFFER_BIT;
279        }
280        if ((mask & GL_STENCIL_BUFFER_BIT) != 0) {
281            if (b.length() > 0) {
282                b.append(" | ");
283            }
284            b.append("GL_STENCIL_BUFFER_BIT");
285            mask &= ~GL_STENCIL_BUFFER_BIT;
286        }
287        if ((mask & GL_COLOR_BUFFER_BIT) != 0) {
288            if (b.length() > 0) {
289                b.append(" | ");
290            }
291            b.append("GL_COLOR_BUFFER_BIT");
292            mask &= ~GL_COLOR_BUFFER_BIT;
293        }
294        if (mask != 0) {
295            if (b.length() > 0) {
296                b.append(" | ");
297            }
298            b.append(getHex(mask));
299        }
300        return b.toString();
301    }
302
303    private String getFactor(int factor) {
304        switch(factor) {
305        case GL_ZERO:
306            return "GL_ZERO";
307        case GL_ONE:
308            return "GL_ONE";
309        case GL_SRC_COLOR:
310            return "GL_SRC_COLOR";
311        case GL_ONE_MINUS_SRC_COLOR:
312            return "GL_ONE_MINUS_SRC_COLOR";
313        case GL_DST_COLOR:
314            return "GL_DST_COLOR";
315        case GL_ONE_MINUS_DST_COLOR:
316            return "GL_ONE_MINUS_DST_COLOR";
317        case GL_SRC_ALPHA:
318            return "GL_SRC_ALPHA";
319        case GL_ONE_MINUS_SRC_ALPHA:
320            return "GL_ONE_MINUS_SRC_ALPHA";
321        case GL_DST_ALPHA:
322            return "GL_DST_ALPHA";
323        case GL_ONE_MINUS_DST_ALPHA:
324            return "GL_ONE_MINUS_DST_ALPHA";
325        case GL_SRC_ALPHA_SATURATE:
326            return "GL_SRC_ALPHA_SATURATE";
327
328        default:
329            return getHex(factor);
330        }
331    }
332
333    private String getShadeModel(int model) {
334        switch(model) {
335        case GL_FLAT:
336            return "GL_FLAT";
337        case GL_SMOOTH:
338            return "GL_SMOOTH";
339        default:
340            return getHex(model);
341        }
342    }
343
344    private String getTextureTarget(int target) {
345        switch (target) {
346        case GL_TEXTURE_2D:
347            return "GL_TEXTURE_2D";
348        default:
349            return getHex(target);
350        }
351    }
352
353    private String getTextureEnvTarget(int target) {
354        switch (target) {
355        case GL_TEXTURE_ENV:
356            return "GL_TEXTURE_ENV";
357        default:
358            return getHex(target);
359        }
360    }
361
362    private String getTextureEnvPName(int pname) {
363        switch (pname) {
364        case GL_TEXTURE_ENV_MODE:
365            return "GL_TEXTURE_ENV_MODE";
366        case GL_TEXTURE_ENV_COLOR:
367            return "GL_TEXTURE_ENV_COLOR";
368        default:
369            return getHex(pname);
370        }
371    }
372
373    private int getTextureEnvParamCount(int pname) {
374        switch (pname) {
375        case GL_TEXTURE_ENV_MODE:
376            return 1;
377        case GL_TEXTURE_ENV_COLOR:
378            return 4;
379        default:
380            return 0;
381        }
382    }
383
384    private String getTextureEnvParamName(float param) {
385        int iparam = (int) param;
386        if (param == (float) iparam) {
387            switch (iparam) {
388            case GL_REPLACE:
389                return "GL_REPLACE";
390            case GL_MODULATE:
391                return "GL_MODULATE";
392            case GL_DECAL:
393                return "GL_DECAL";
394            case GL_BLEND:
395                return "GL_BLEND";
396            case GL_ADD:
397                return "GL_ADD";
398            case GL_COMBINE:
399                return "GL_COMBINE";
400            default:
401                return getHex(iparam);
402            }
403        }
404        return Float.toString(param);
405    }
406
407    private String getMatrixMode(int matrixMode) {
408        switch (matrixMode) {
409        case GL_MODELVIEW:
410            return "GL_MODELVIEW";
411        case GL_PROJECTION:
412            return "GL_PROJECTION";
413        case GL_TEXTURE:
414            return "GL_TEXTURE";
415        default:
416            return getHex(matrixMode);
417        }
418    }
419
420    private String getClientState(int clientState) {
421        switch (clientState) {
422        case GL_COLOR_ARRAY:
423            return "GL_COLOR_ARRAY";
424        case GL_VERTEX_ARRAY:
425            return "GL_VERTEX_ARRAY";
426        case GL_NORMAL_ARRAY:
427            return "GL_NORMAL_ARRAY";
428        case GL_TEXTURE_COORD_ARRAY:
429            return "GL_TEXTURE_COORD_ARRAY";
430        default:
431            return getHex(clientState);
432        }
433    }
434
435    private String getCap(int cap) {
436        switch (cap) {
437        case GL_FOG:
438            return "GL_FOG";
439        case GL_LIGHTING:
440            return "GL_LIGHTING";
441        case GL_TEXTURE_2D:
442            return "GL_TEXTURE_2D";
443        case GL_CULL_FACE:
444            return "GL_CULL_FACE";
445        case GL_ALPHA_TEST:
446            return "GL_ALPHA_TEST";
447        case GL_BLEND:
448            return "GL_BLEND";
449        case GL_COLOR_LOGIC_OP:
450            return "GL_COLOR_LOGIC_OP";
451        case GL_DITHER:
452            return "GL_DITHER";
453        case GL_STENCIL_TEST:
454            return "GL_STENCIL_TEST";
455        case GL_DEPTH_TEST:
456            return "GL_DEPTH_TEST";
457        case GL_LIGHT0:
458            return "GL_LIGHT0";
459        case GL_LIGHT1:
460            return "GL_LIGHT1";
461        case GL_LIGHT2:
462            return "GL_LIGHT2";
463        case GL_LIGHT3:
464            return "GL_LIGHT3";
465        case GL_LIGHT4:
466            return "GL_LIGHT4";
467        case GL_LIGHT5:
468            return "GL_LIGHT5";
469        case GL_LIGHT6:
470            return "GL_LIGHT6";
471        case GL_LIGHT7:
472            return "GL_LIGHT7";
473        case GL_POINT_SMOOTH:
474            return "GL_POINT_SMOOTH";
475        case GL_LINE_SMOOTH:
476            return "GL_LINE_SMOOTH";
477        case GL_COLOR_MATERIAL:
478            return "GL_COLOR_MATERIAL";
479        case GL_NORMALIZE:
480            return "GL_NORMALIZE";
481        case GL_RESCALE_NORMAL:
482            return "GL_RESCALE_NORMAL";
483        case GL_VERTEX_ARRAY:
484            return "GL_VERTEX_ARRAY";
485        case GL_NORMAL_ARRAY:
486            return "GL_NORMAL_ARRAY";
487        case GL_COLOR_ARRAY:
488            return "GL_COLOR_ARRAY";
489        case GL_TEXTURE_COORD_ARRAY:
490            return "GL_TEXTURE_COORD_ARRAY";
491        case GL_MULTISAMPLE:
492            return "GL_MULTISAMPLE";
493        case GL_SAMPLE_ALPHA_TO_COVERAGE:
494            return "GL_SAMPLE_ALPHA_TO_COVERAGE";
495        case GL_SAMPLE_ALPHA_TO_ONE:
496            return "GL_SAMPLE_ALPHA_TO_ONE";
497        case GL_SAMPLE_COVERAGE:
498            return "GL_SAMPLE_COVERAGE";
499        case GL_SCISSOR_TEST:
500            return "GL_SCISSOR_TEST";
501        default:
502            return getHex(cap);
503        }
504    }
505
506    private String getTexturePName(int pname) {
507        switch (pname) {
508        case GL_TEXTURE_MAG_FILTER:
509            return "GL_TEXTURE_MAG_FILTER";
510        case GL_TEXTURE_MIN_FILTER:
511            return "GL_TEXTURE_MIN_FILTER";
512        case GL_TEXTURE_WRAP_S:
513            return "GL_TEXTURE_WRAP_S";
514        case GL_TEXTURE_WRAP_T:
515            return "GL_TEXTURE_WRAP_T";
516        case GL_GENERATE_MIPMAP:
517            return "GL_GENERATE_MIPMAP";
518        case GL_TEXTURE_CROP_RECT_OES:
519            return "GL_TEXTURE_CROP_RECT_OES";
520        default:
521            return getHex(pname);
522        }
523    }
524
525    private String getTextureParamName(float param) {
526        int iparam = (int) param;
527        if (param == (float) iparam) {
528            switch (iparam) {
529            case GL_CLAMP_TO_EDGE:
530                return "GL_CLAMP_TO_EDGE";
531            case GL_REPEAT:
532                return "GL_REPEAT";
533            case GL_NEAREST:
534                return "GL_NEAREST";
535            case GL_LINEAR:
536                return "GL_LINEAR";
537            case GL_NEAREST_MIPMAP_NEAREST:
538                return "GL_NEAREST_MIPMAP_NEAREST";
539            case GL_LINEAR_MIPMAP_NEAREST:
540                return "GL_LINEAR_MIPMAP_NEAREST";
541            case GL_NEAREST_MIPMAP_LINEAR:
542                return "GL_NEAREST_MIPMAP_LINEAR";
543            case GL_LINEAR_MIPMAP_LINEAR:
544                return "GL_LINEAR_MIPMAP_LINEAR";
545            default:
546                return getHex(iparam);
547            }
548        }
549        return Float.toString(param);
550    }
551
552    private String getFogPName(int pname) {
553        switch (pname) {
554        case GL_FOG_DENSITY:
555            return "GL_FOG_DENSITY";
556        case GL_FOG_START:
557            return "GL_FOG_START";
558        case GL_FOG_END:
559            return "GL_FOG_END";
560        case GL_FOG_MODE:
561            return "GL_FOG_MODE";
562        case GL_FOG_COLOR:
563            return "GL_FOG_COLOR";
564        default:
565            return getHex(pname);
566        }
567    }
568
569    private int getFogParamCount(int pname) {
570        switch (pname) {
571        case GL_FOG_DENSITY:
572            return 1;
573        case GL_FOG_START:
574            return 1;
575        case GL_FOG_END:
576            return 1;
577        case GL_FOG_MODE:
578            return 1;
579        case GL_FOG_COLOR:
580            return 4;
581        default:
582            return 0;
583        }
584    }
585
586    private String getBeginMode(int mode) {
587        switch (mode) {
588        case GL_POINTS:
589            return "GL_POINTS";
590        case GL_LINES:
591            return "GL_LINES";
592        case GL_LINE_LOOP:
593            return "GL_LINE_LOOP";
594        case GL_LINE_STRIP:
595            return "GL_LINE_STRIP";
596        case GL_TRIANGLES:
597            return "GL_TRIANGLES";
598        case GL_TRIANGLE_STRIP:
599            return "GL_TRIANGLE_STRIP";
600        case GL_TRIANGLE_FAN:
601            return "GL_TRIANGLE_FAN";
602        default:
603            return getHex(mode);
604        }
605    }
606
607    private String getIndexType(int type) {
608        switch (type) {
609        case GL_UNSIGNED_SHORT:
610            return "GL_UNSIGNED_SHORT";
611        case GL_UNSIGNED_BYTE:
612            return "GL_UNSIGNED_BYTE";
613        default:
614            return getHex(type);
615        }
616    }
617
618    private String getIntegerStateName(int pname) {
619        switch (pname) {
620        case GL_ALPHA_BITS:
621            return "GL_ALPHA_BITS";
622        case GL_ALIASED_LINE_WIDTH_RANGE:
623            return "GL_ALIASED_LINE_WIDTH_RANGE";
624        case GL_ALIASED_POINT_SIZE_RANGE:
625            return "GL_ALIASED_POINT_SIZE_RANGE";
626        case GL_BLUE_BITS:
627            return "GL_BLUE_BITS";
628        case GL_COMPRESSED_TEXTURE_FORMATS:
629            return "GL_COMPRESSED_TEXTURE_FORMATS";
630        case GL_DEPTH_BITS:
631            return "GL_DEPTH_BITS";
632        case GL_GREEN_BITS:
633            return "GL_GREEN_BITS";
634        case GL_MAX_ELEMENTS_INDICES:
635            return "GL_MAX_ELEMENTS_INDICES";
636        case GL_MAX_ELEMENTS_VERTICES:
637            return "GL_MAX_ELEMENTS_VERTICES";
638        case GL_MAX_LIGHTS:
639            return "GL_MAX_LIGHTS";
640        case GL_MAX_TEXTURE_SIZE:
641            return "GL_MAX_TEXTURE_SIZE";
642        case GL_MAX_VIEWPORT_DIMS:
643            return "GL_MAX_VIEWPORT_DIMS";
644        case GL_MAX_MODELVIEW_STACK_DEPTH:
645            return "GL_MAX_MODELVIEW_STACK_DEPTH";
646        case GL_MAX_PROJECTION_STACK_DEPTH:
647            return "GL_MAX_PROJECTION_STACK_DEPTH";
648        case GL_MAX_TEXTURE_STACK_DEPTH:
649            return "GL_MAX_TEXTURE_STACK_DEPTH";
650        case GL_MAX_TEXTURE_UNITS:
651            return "GL_MAX_TEXTURE_UNITS";
652        case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
653            return "GL_NUM_COMPRESSED_TEXTURE_FORMATS";
654        case GL_RED_BITS:
655            return "GL_RED_BITS";
656        case GL_SMOOTH_LINE_WIDTH_RANGE:
657            return "GL_SMOOTH_LINE_WIDTH_RANGE";
658        case GL_SMOOTH_POINT_SIZE_RANGE:
659            return "GL_SMOOTH_POINT_SIZE_RANGE";
660        case GL_STENCIL_BITS:
661            return "GL_STENCIL_BITS";
662        case GL_SUBPIXEL_BITS:
663            return "GL_SUBPIXEL_BITS";
664
665        case GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES:
666            return "GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES";
667        case GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES:
668            return "GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES";
669        case GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES:
670            return "GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES";
671
672        default:
673            return getHex(pname);
674        }
675    }
676
677    private int getIntegerStateSize(int pname) {
678        switch (pname) {
679        case GL_ALPHA_BITS:
680            return 1;
681        case GL_ALIASED_LINE_WIDTH_RANGE:
682            return 2;
683        case GL_ALIASED_POINT_SIZE_RANGE:
684            return 2;
685        case GL_BLUE_BITS:
686            return 1;
687        case GL_COMPRESSED_TEXTURE_FORMATS:
688            // Have to ask the implementation for the size
689        {
690            int[] buffer = new int[1];
691            mgl.glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, buffer, 0);
692            return buffer[0];
693        }
694        case GL_DEPTH_BITS:
695            return 1;
696        case GL_GREEN_BITS:
697            return 1;
698        case GL_MAX_ELEMENTS_INDICES:
699            return 1;
700        case GL_MAX_ELEMENTS_VERTICES:
701            return 1;
702        case GL_MAX_LIGHTS:
703            return 1;
704        case GL_MAX_TEXTURE_SIZE:
705            return 1;
706        case GL_MAX_VIEWPORT_DIMS:
707            return 2;
708        case GL_MAX_MODELVIEW_STACK_DEPTH:
709            return 1;
710        case GL_MAX_PROJECTION_STACK_DEPTH:
711            return 1;
712        case GL_MAX_TEXTURE_STACK_DEPTH:
713            return 1;
714        case GL_MAX_TEXTURE_UNITS:
715            return 1;
716        case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
717            return 1;
718        case GL_RED_BITS:
719            return 1;
720        case GL_SMOOTH_LINE_WIDTH_RANGE:
721            return 2;
722        case GL_SMOOTH_POINT_SIZE_RANGE:
723            return 2;
724        case GL_STENCIL_BITS:
725            return 1;
726        case GL_SUBPIXEL_BITS:
727            return 1;
728
729        case GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES:
730        case GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES:
731        case GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES:
732            return 16;
733
734        default:
735            return 0;
736        }
737    }
738
739    private int getIntegerStateFormat(int pname) {
740        switch (pname) {
741        case GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES:
742        case GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES:
743        case GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES:
744            return FORMAT_FLOAT;
745
746        default:
747            return FORMAT_INT;
748        }
749    }
750
751    private String getHintTarget(int target) {
752        switch (target) {
753        case GL_FOG_HINT:
754            return "GL_FOG_HINT";
755        case GL_LINE_SMOOTH_HINT:
756            return "GL_LINE_SMOOTH_HINT";
757        case GL_PERSPECTIVE_CORRECTION_HINT:
758            return "GL_PERSPECTIVE_CORRECTION_HINT";
759        case GL_POINT_SMOOTH_HINT:
760            return "GL_POINT_SMOOTH_HINT";
761        case GL_POLYGON_SMOOTH_HINT:
762            return "GL_POLYGON_SMOOTH_HINT";
763        case GL_GENERATE_MIPMAP_HINT:
764            return "GL_GENERATE_MIPMAP_HINT";
765        default:
766            return getHex(target);
767        }
768    }
769
770    private String getHintMode(int mode) {
771        switch (mode) {
772        case GL_FASTEST:
773            return "GL_FASTEST";
774        case GL_NICEST:
775            return "GL_NICEST";
776        case GL_DONT_CARE:
777            return "GL_DONT_CARE";
778        default:
779            return getHex(mode);
780        }
781    }
782
783    private String getFaceName(int face) {
784        switch (face) {
785        case GL_FRONT_AND_BACK:
786            return "GL_FRONT_AND_BACK";
787        default:
788            return getHex(face);
789        }
790    }
791
792    private String getMaterialPName(int pname) {
793        switch (pname) {
794        case GL_AMBIENT:
795            return "GL_AMBIENT";
796        case GL_DIFFUSE:
797            return "GL_DIFFUSE";
798        case GL_SPECULAR:
799            return "GL_SPECULAR";
800        case GL_EMISSION:
801            return "GL_EMISSION";
802        case GL_SHININESS:
803            return "GL_SHININESS";
804        case GL_AMBIENT_AND_DIFFUSE:
805            return "GL_AMBIENT_AND_DIFFUSE";
806        default:
807            return getHex(pname);
808        }
809    }
810
811    private int getMaterialParamCount(int pname) {
812        switch (pname) {
813        case GL_AMBIENT:
814            return 4;
815        case GL_DIFFUSE:
816            return 4;
817        case GL_SPECULAR:
818            return 4;
819        case GL_EMISSION:
820            return 4;
821        case GL_SHININESS:
822            return 1;
823        case GL_AMBIENT_AND_DIFFUSE:
824            return 4;
825        default:
826            return 0;
827        }
828    }
829
830    private String getLightName(int light) {
831        if (light >= GL_LIGHT0 && light <= GL_LIGHT7) {
832            return "GL_LIGHT" + Integer.toString(light);
833        }
834        return getHex(light);
835    }
836
837    private String getLightPName(int pname) {
838        switch (pname) {
839        case GL_AMBIENT:
840            return "GL_AMBIENT";
841        case GL_DIFFUSE:
842            return "GL_DIFFUSE";
843        case GL_SPECULAR:
844            return "GL_SPECULAR";
845        case GL_POSITION:
846            return "GL_POSITION";
847        case GL_SPOT_DIRECTION:
848            return "GL_SPOT_DIRECTION";
849        case GL_SPOT_EXPONENT:
850            return "GL_SPOT_EXPONENT";
851        case GL_SPOT_CUTOFF:
852            return "GL_SPOT_CUTOFF";
853        case GL_CONSTANT_ATTENUATION:
854            return "GL_CONSTANT_ATTENUATION";
855        case GL_LINEAR_ATTENUATION:
856            return "GL_LINEAR_ATTENUATION";
857        case GL_QUADRATIC_ATTENUATION:
858            return "GL_QUADRATIC_ATTENUATION";
859        default:
860            return getHex(pname);
861        }
862    }
863
864    private int getLightParamCount(int pname) {
865        switch (pname) {
866        case GL_AMBIENT:
867            return 4;
868        case GL_DIFFUSE:
869            return 4;
870        case GL_SPECULAR:
871            return 4;
872        case GL_POSITION:
873            return 4;
874        case GL_SPOT_DIRECTION:
875            return 3;
876        case GL_SPOT_EXPONENT:
877            return 1;
878        case GL_SPOT_CUTOFF:
879            return 1;
880        case GL_CONSTANT_ATTENUATION:
881            return 1;
882        case GL_LINEAR_ATTENUATION:
883            return 1;
884        case GL_QUADRATIC_ATTENUATION:
885            return 1;
886        default:
887            return 0;
888        }
889    }
890
891    private String getLightModelPName(int pname) {
892        switch (pname) {
893        case GL_LIGHT_MODEL_AMBIENT:
894            return "GL_LIGHT_MODEL_AMBIENT";
895        case GL_LIGHT_MODEL_TWO_SIDE:
896            return "GL_LIGHT_MODEL_TWO_SIDE";
897        default:
898            return getHex(pname);
899        }
900    }
901
902    private int getLightModelParamCount(int pname) {
903        switch (pname) {
904        case GL_LIGHT_MODEL_AMBIENT:
905            return 4;
906        case GL_LIGHT_MODEL_TWO_SIDE:
907            return 1;
908        default:
909            return 0;
910        }
911    }
912
913    private String getPointerTypeName(int type) {
914        switch (type) {
915        case GL_BYTE:
916            return "GL_BYTE";
917        case GL_UNSIGNED_BYTE:
918            return "GL_UNSIGNED_BYTE";
919        case GL_SHORT:
920            return "GL_SHORT";
921        case GL_FIXED:
922            return "GL_FIXED";
923        case GL_FLOAT:
924            return "GL_FLOAT";
925        default:
926            return getHex(type);
927        }
928    }
929
930    private ByteBuffer toByteBuffer(int byteCount, Buffer input) {
931        ByteBuffer result = null;
932        boolean convertWholeBuffer = (byteCount < 0);
933        if (input instanceof ByteBuffer) {
934            ByteBuffer input2 = (ByteBuffer) input;
935            int position = input2.position();
936            if (convertWholeBuffer) {
937                byteCount = input2.limit() - position;
938            }
939            result = ByteBuffer.allocate(byteCount).order(input2.order());
940            for (int i = 0; i < byteCount; i++) {
941                result.put(input2.get());
942            }
943            input2.position(position);
944        } else if (input instanceof CharBuffer) {
945            CharBuffer input2 = (CharBuffer) input;
946            int position = input2.position();
947            if (convertWholeBuffer) {
948                byteCount = (input2.limit() - position) * 2;
949            }
950            result = ByteBuffer.allocate(byteCount).order(input2.order());
951            CharBuffer result2 = result.asCharBuffer();
952            for (int i = 0; i < byteCount / 2; i++) {
953                result2.put(input2.get());
954            }
955            input2.position(position);
956        } else if (input instanceof ShortBuffer) {
957            ShortBuffer input2 = (ShortBuffer) input;
958            int position = input2.position();
959            if (convertWholeBuffer) {
960                byteCount = (input2.limit() - position)* 2;
961            }
962            result = ByteBuffer.allocate(byteCount).order(input2.order());
963            ShortBuffer result2 = result.asShortBuffer();
964            for (int i = 0; i < byteCount / 2; i++) {
965                result2.put(input2.get());
966            }
967            input2.position(position);
968        } else if (input instanceof IntBuffer) {
969            IntBuffer input2 = (IntBuffer) input;
970            int position = input2.position();
971            if (convertWholeBuffer) {
972                byteCount = (input2.limit() - position) * 4;
973            }
974            result = ByteBuffer.allocate(byteCount).order(input2.order());
975            IntBuffer result2 = result.asIntBuffer();
976            for (int i = 0; i < byteCount / 4; i++) {
977                result2.put(input2.get());
978            }
979            input2.position(position);
980        } else if (input instanceof FloatBuffer) {
981            FloatBuffer input2 = (FloatBuffer) input;
982            int position = input2.position();
983            if (convertWholeBuffer) {
984                byteCount = (input2.limit() - position) * 4;
985            }
986            result = ByteBuffer.allocate(byteCount).order(input2.order());
987            FloatBuffer result2 = result.asFloatBuffer();
988            for (int i = 0; i < byteCount / 4; i++) {
989                result2.put(input2.get());
990            }
991            input2.position(position);
992        } else if (input instanceof DoubleBuffer) {
993            DoubleBuffer input2 = (DoubleBuffer) input;
994            int position = input2.position();
995            if (convertWholeBuffer) {
996                byteCount = (input2.limit() - position) * 8;
997            }
998            result = ByteBuffer.allocate(byteCount).order(input2.order());
999            DoubleBuffer result2 = result.asDoubleBuffer();
1000            for (int i = 0; i < byteCount / 8; i++) {
1001                result2.put(input2.get());
1002            }
1003            input2.position(position);
1004        } else if (input instanceof LongBuffer) {
1005            LongBuffer input2 = (LongBuffer) input;
1006            int position = input2.position();
1007            if (convertWholeBuffer) {
1008                byteCount = (input2.limit() - position) * 8;
1009            }
1010            result = ByteBuffer.allocate(byteCount).order(input2.order());
1011            LongBuffer result2 = result.asLongBuffer();
1012            for (int i = 0; i < byteCount / 8; i++) {
1013                result2.put(input2.get());
1014            }
1015            input2.position(position);
1016        } else {
1017            throw new RuntimeException("Unimplemented Buffer subclass.");
1018        }
1019        result.rewind();
1020        // The OpenGL API will interpret the result in hardware byte order,
1021        // so we better do that as well:
1022        result.order(ByteOrder.nativeOrder());
1023        return result;
1024    }
1025
1026    private char[] toCharIndices(int count, int type, Buffer indices) {
1027        char[] result = new char[count];
1028        switch (type) {
1029        case GL_UNSIGNED_BYTE: {
1030            ByteBuffer byteBuffer = toByteBuffer(count, indices);
1031            byte[] array = byteBuffer.array();
1032            int offset = byteBuffer.arrayOffset();
1033            for (int i = 0; i < count; i++) {
1034                result[i] = (char) (0xff & array[offset + i]);
1035            }
1036        }
1037            break;
1038        case GL_UNSIGNED_SHORT: {
1039            CharBuffer charBuffer;
1040            if (indices instanceof CharBuffer) {
1041                charBuffer = (CharBuffer) indices;
1042            } else {
1043                ByteBuffer byteBuffer = toByteBuffer(count * 2, indices);
1044                charBuffer = byteBuffer.asCharBuffer();
1045            }
1046            int oldPosition = charBuffer.position();
1047            charBuffer.position(0);
1048            charBuffer.get(result);
1049            charBuffer.position(oldPosition);
1050        }
1051            break;
1052        default:
1053            // Don't throw an exception, because we don't want logging to
1054            // change the behavior.
1055            break;
1056        }
1057        return result;
1058    }
1059
1060    private void doArrayElement(StringBuilder builder, boolean enabled,
1061            String name, PointerInfo pointer, int index) {
1062        if (!enabled) {
1063            return;
1064        }
1065        builder.append(" ");
1066        builder.append(name + ":{");
1067        if (pointer == null || pointer.mTempByteBuffer == null ) {
1068            builder.append("undefined }");
1069            return;
1070        }
1071        if (pointer.mStride < 0) {
1072            builder.append("invalid stride");
1073            return;
1074        }
1075
1076        int stride = pointer.getStride();
1077        ByteBuffer byteBuffer = pointer.mTempByteBuffer;
1078        int size = pointer.mSize;
1079        int type = pointer.mType;
1080        int sizeofType = pointer.sizeof(type);
1081        int byteOffset = stride * index;
1082        for (int i = 0; i < size; i++) {
1083            if (i > 0) {
1084                builder.append(", ");
1085            }
1086            switch (type) {
1087            case GL_BYTE: {
1088                byte d = byteBuffer.get(byteOffset);
1089                builder.append(Integer.toString(d));
1090            }
1091                break;
1092            case GL_UNSIGNED_BYTE: {
1093                byte d = byteBuffer.get(byteOffset);
1094                builder.append(Integer.toString(0xff & d));
1095            }
1096                break;
1097            case GL_SHORT: {
1098                ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
1099                short d = shortBuffer.get(byteOffset / 2);
1100                builder.append(Integer.toString(d));
1101            }
1102                break;
1103            case GL_FIXED: {
1104                IntBuffer intBuffer = byteBuffer.asIntBuffer();
1105                int d = intBuffer.get(byteOffset / 4);
1106                builder.append(Integer.toString(d));
1107            }
1108                break;
1109            case GL_FLOAT: {
1110                FloatBuffer intBuffer = byteBuffer.asFloatBuffer();
1111                float d = intBuffer.get(byteOffset / 4);
1112                builder.append(Float.toString(d));
1113            }
1114                break;
1115            default:
1116                builder.append("?");
1117                break;
1118            }
1119            byteOffset += sizeofType;
1120        }
1121        builder.append("}");
1122    }
1123
1124    private void doElement(StringBuilder builder, int ordinal, int vertexIndex) {
1125        builder.append(" [" + ordinal + " : " + vertexIndex + "] =");
1126        doArrayElement(builder, mVertexArrayEnabled, "v", mVertexPointer,
1127                vertexIndex);
1128        doArrayElement(builder, mNormalArrayEnabled, "n", mNormalPointer,
1129                vertexIndex);
1130        doArrayElement(builder, mColorArrayEnabled, "c", mColorPointer,
1131                vertexIndex);
1132        doArrayElement(builder, mTextureCoordArrayEnabled, "t",
1133                mTexCoordPointer, vertexIndex);
1134        builder.append("\n");
1135        // Vertex
1136        // Normal
1137        // Color
1138        // TexCoord
1139    }
1140
1141    private void bindArrays() {
1142        if (mColorArrayEnabled)
1143            mColorPointer.bindByteBuffer();
1144        if (mNormalArrayEnabled)
1145            mNormalPointer.bindByteBuffer();
1146        if (mTextureCoordArrayEnabled)
1147            mTexCoordPointer.bindByteBuffer();
1148        if (mVertexArrayEnabled)
1149            mVertexPointer.bindByteBuffer();
1150    }
1151
1152    private void unbindArrays() {
1153        if (mColorArrayEnabled)
1154            mColorPointer.unbindByteBuffer();
1155        if (mNormalArrayEnabled)
1156            mNormalPointer.unbindByteBuffer();
1157        if (mTextureCoordArrayEnabled)
1158            mTexCoordPointer.unbindByteBuffer();
1159        if (mVertexArrayEnabled)
1160            mVertexPointer.unbindByteBuffer();
1161    }
1162
1163    private void startLogIndices() {
1164        mStringBuilder = new StringBuilder();
1165        mStringBuilder.append("\n");
1166        bindArrays();
1167    }
1168
1169    private void endLogIndices() {
1170        log(mStringBuilder.toString());
1171        unbindArrays();
1172    }
1173
1174    // ---------------------------------------------------------------------
1175    // GL10 methods:
1176
1177    public void glActiveTexture(int texture) {
1178        begin("glActiveTexture");
1179        arg("texture", texture);
1180        end();
1181        mgl.glActiveTexture(texture);
1182        checkError();
1183    }
1184
1185    public void glAlphaFunc(int func, float ref) {
1186        begin("glAlphaFunc");
1187        arg("func", func);
1188        arg("ref", ref);
1189        end();
1190        mgl.glAlphaFunc(func, ref);
1191        checkError();
1192    }
1193
1194    public void glAlphaFuncx(int func, int ref) {
1195        begin("glAlphaFuncx");
1196        arg("func", func);
1197        arg("ref", ref);
1198        end();
1199        mgl.glAlphaFuncx(func, ref);
1200        checkError();
1201    }
1202
1203    public void glBindTexture(int target, int texture) {
1204        begin("glBindTexture");
1205        arg("target", getTextureTarget(target));
1206        arg("texture", texture);
1207        end();
1208        mgl.glBindTexture(target, texture);
1209        checkError();
1210    }
1211
1212    public void glBlendFunc(int sfactor, int dfactor) {
1213        begin("glBlendFunc");
1214        arg("sfactor", getFactor(sfactor));
1215        arg("dfactor", getFactor(dfactor));
1216        end();
1217
1218        mgl.glBlendFunc(sfactor, dfactor);
1219        checkError();
1220    }
1221
1222    public void glClear(int mask) {
1223        begin("glClear");
1224        arg("mask", getClearBufferMask(mask));
1225        end();
1226
1227        mgl.glClear(mask);
1228        checkError();
1229    }
1230
1231    public void glClearColor(float red, float green, float blue, float alpha) {
1232        begin("glClearColor");
1233        arg("red", red);
1234        arg("green", green);
1235        arg("blue", blue);
1236        arg("alpha", alpha);
1237        end();
1238
1239        mgl.glClearColor(red, green, blue, alpha);
1240        checkError();
1241    }
1242
1243    public void glClearColorx(int red, int green, int blue, int alpha) {
1244        begin("glClearColor");
1245        arg("red", red);
1246        arg("green", green);
1247        arg("blue", blue);
1248        arg("alpha", alpha);
1249        end();
1250
1251        mgl.glClearColorx(red, green, blue, alpha);
1252        checkError();
1253    }
1254
1255    public void glClearDepthf(float depth) {
1256        begin("glClearDepthf");
1257        arg("depth", depth);
1258        end();
1259
1260        mgl.glClearDepthf(depth);
1261        checkError();
1262    }
1263
1264    public void glClearDepthx(int depth) {
1265        begin("glClearDepthx");
1266        arg("depth", depth);
1267        end();
1268
1269        mgl.glClearDepthx(depth);
1270        checkError();
1271    }
1272
1273    public void glClearStencil(int s) {
1274        begin("glClearStencil");
1275        arg("s", s);
1276        end();
1277
1278        mgl.glClearStencil(s);
1279        checkError();
1280    }
1281
1282    public void glClientActiveTexture(int texture) {
1283        begin("glClientActiveTexture");
1284        arg("texture", texture);
1285        end();
1286
1287        mgl.glClientActiveTexture(texture);
1288        checkError();
1289    }
1290
1291    public void glColor4f(float red, float green, float blue, float alpha) {
1292        begin("glColor4f");
1293        arg("red", red);
1294        arg("green", green);
1295        arg("blue", blue);
1296        arg("alpha", alpha);
1297        end();
1298
1299        mgl.glColor4f(red, green, blue, alpha);
1300        checkError();
1301    }
1302
1303    public void glColor4x(int red, int green, int blue, int alpha) {
1304        begin("glColor4x");
1305        arg("red", red);
1306        arg("green", green);
1307        arg("blue", blue);
1308        arg("alpha", alpha);
1309        end();
1310
1311        mgl.glColor4x(red, green, blue, alpha);
1312        checkError();
1313    }
1314
1315    public void glColorMask(boolean red, boolean green, boolean blue,
1316            boolean alpha) {
1317        begin("glColorMask");
1318        arg("red", red);
1319        arg("green", green);
1320        arg("blue", blue);
1321        arg("alpha", alpha);
1322        end();
1323
1324        mgl.glColorMask(red, green, blue, alpha);
1325        checkError();
1326    }
1327
1328    public void glColorPointer(int size, int type, int stride, Buffer pointer) {
1329        begin("glColorPointer");
1330        argPointer(size, type, stride, pointer);
1331        end();
1332        mColorPointer = new PointerInfo(size, type, stride, pointer);
1333
1334        mgl.glColorPointer(size, type, stride, pointer);
1335        checkError();
1336    }
1337
1338    public void glCompressedTexImage2D(int target, int level,
1339            int internalformat, int width, int height, int border,
1340            int imageSize, Buffer data) {
1341        begin("glCompressedTexImage2D");
1342        arg("target", getTextureTarget(target));
1343        arg("level", level);
1344        arg("internalformat", internalformat);
1345        arg("width", width);
1346        arg("height", height);
1347        arg("border", border);
1348        arg("imageSize", imageSize);
1349        arg("data", data.toString());
1350        end();
1351
1352        mgl.glCompressedTexImage2D(target, level, internalformat, width,
1353                height, border, imageSize, data);
1354        checkError();
1355    }
1356
1357    public void glCompressedTexSubImage2D(int target, int level, int xoffset,
1358            int yoffset, int width, int height, int format, int imageSize,
1359            Buffer data) {
1360        begin("glCompressedTexSubImage2D");
1361        arg("target", getTextureTarget(target));
1362        arg("level", level);
1363        arg("xoffset", xoffset);
1364        arg("yoffset", yoffset);
1365        arg("width", width);
1366        arg("height", height);
1367        arg("format", format);
1368        arg("imageSize", imageSize);
1369        arg("data", data.toString());
1370        end();
1371
1372        mgl.glCompressedTexSubImage2D(target, level, xoffset, yoffset, width,
1373                height, format, imageSize, data);
1374        checkError();
1375    }
1376
1377    public void glCopyTexImage2D(int target, int level, int internalformat,
1378            int x, int y, int width, int height, int border) {
1379        begin("glCopyTexImage2D");
1380        arg("target", getTextureTarget(target));
1381        arg("level", level);
1382        arg("internalformat", internalformat);
1383        arg("x", x);
1384        arg("y", y);
1385        arg("width", width);
1386        arg("height", height);
1387        arg("border", border);
1388        end();
1389
1390        mgl.glCopyTexImage2D(target, level, internalformat, x, y, width,
1391                height, border);
1392        checkError();
1393    }
1394
1395    public void glCopyTexSubImage2D(int target, int level, int xoffset,
1396            int yoffset, int x, int y, int width, int height) {
1397        begin("glCopyTexSubImage2D");
1398        arg("target", getTextureTarget(target));
1399        arg("level", level);
1400        arg("xoffset", xoffset);
1401        arg("yoffset", yoffset);
1402        arg("x", x);
1403        arg("y", y);
1404        arg("width", width);
1405        arg("height", height);
1406        end();
1407
1408        mgl.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width,
1409                height);
1410        checkError();
1411    }
1412
1413    public void glCullFace(int mode) {
1414        begin("glCullFace");
1415        arg("mode", mode);
1416        end();
1417
1418        mgl.glCullFace(mode);
1419        checkError();
1420    }
1421
1422    public void glDeleteTextures(int n, int[] textures, int offset) {
1423        begin("glDeleteTextures");
1424        arg("n", n);
1425        arg("textures", n, textures, offset);
1426        arg("offset", offset);
1427        end();
1428
1429        mgl.glDeleteTextures(n, textures, offset);
1430        checkError();
1431    }
1432
1433    public void glDeleteTextures(int n, IntBuffer textures) {
1434        begin("glDeleteTextures");
1435        arg("n", n);
1436        arg("textures", n, textures);
1437        end();
1438
1439        mgl.glDeleteTextures(n, textures);
1440        checkError();
1441    }
1442
1443    public void glDepthFunc(int func) {
1444        begin("glDepthFunc");
1445        arg("func", func);
1446        end();
1447
1448        mgl.glDepthFunc(func);
1449        checkError();
1450    }
1451
1452    public void glDepthMask(boolean flag) {
1453        begin("glDepthMask");
1454        arg("flag", flag);
1455        end();
1456
1457        mgl.glDepthMask(flag);
1458        checkError();
1459    }
1460
1461    public void glDepthRangef(float near, float far) {
1462        begin("glDepthRangef");
1463        arg("near", near);
1464        arg("far", far);
1465        end();
1466
1467        mgl.glDepthRangef(near, far);
1468        checkError();
1469    }
1470
1471    public void glDepthRangex(int near, int far) {
1472        begin("glDepthRangex");
1473        arg("near", near);
1474        arg("far", far);
1475        end();
1476
1477        mgl.glDepthRangex(near, far);
1478        checkError();
1479    }
1480
1481    public void glDisable(int cap) {
1482        begin("glDisable");
1483        arg("cap", getCap(cap));
1484        end();
1485
1486        mgl.glDisable(cap);
1487        checkError();
1488    }
1489
1490    public void glDisableClientState(int array) {
1491        begin("glDisableClientState");
1492        arg("array", getClientState(array));
1493        end();
1494
1495        switch (array) {
1496        case GL_COLOR_ARRAY:
1497            mColorArrayEnabled = false;
1498            break;
1499        case GL_NORMAL_ARRAY:
1500            mNormalArrayEnabled = false;
1501            break;
1502        case GL_TEXTURE_COORD_ARRAY:
1503            mTextureCoordArrayEnabled = false;
1504            break;
1505        case GL_VERTEX_ARRAY:
1506            mVertexArrayEnabled = false;
1507            break;
1508        }
1509        mgl.glDisableClientState(array);
1510        checkError();
1511    }
1512
1513    public void glDrawArrays(int mode, int first, int count) {
1514        begin("glDrawArrays");
1515        arg("mode", mode);
1516        arg("first", first);
1517        arg("count", count);
1518        startLogIndices();
1519        for (int i = 0; i < count; i++) {
1520            doElement(mStringBuilder, i, first + i);
1521        }
1522        endLogIndices();
1523        end();
1524
1525        mgl.glDrawArrays(mode, first, count);
1526        checkError();
1527    }
1528
1529    public void glDrawElements(int mode, int count, int type, Buffer indices) {
1530        begin("glDrawElements");
1531        arg("mode", getBeginMode(mode));
1532        arg("count", count);
1533        arg("type", getIndexType(type));
1534        char[] indexArray = toCharIndices(count, type, indices);
1535        int indexArrayLength = indexArray.length;
1536        startLogIndices();
1537        for (int i = 0; i < indexArrayLength; i++) {
1538            doElement(mStringBuilder, i, indexArray[i]);
1539        }
1540        endLogIndices();
1541        end();
1542
1543        mgl.glDrawElements(mode, count, type, indices);
1544        checkError();
1545    }
1546
1547    public void glEnable(int cap) {
1548        begin("glEnable");
1549        arg("cap", getCap(cap));
1550        end();
1551
1552        mgl.glEnable(cap);
1553        checkError();
1554    }
1555
1556    public void glEnableClientState(int array) {
1557        begin("glEnableClientState");
1558        arg("array", getClientState(array));
1559        end();
1560
1561        switch (array) {
1562        case GL_COLOR_ARRAY:
1563            mColorArrayEnabled = true;
1564            break;
1565        case GL_NORMAL_ARRAY:
1566            mNormalArrayEnabled = true;
1567            break;
1568        case GL_TEXTURE_COORD_ARRAY:
1569            mTextureCoordArrayEnabled = true;
1570            break;
1571        case GL_VERTEX_ARRAY:
1572            mVertexArrayEnabled = true;
1573            break;
1574        }
1575        mgl.glEnableClientState(array);
1576        checkError();
1577    }
1578
1579    public void glFinish() {
1580        begin("glFinish");
1581        end();
1582
1583        mgl.glFinish();
1584        checkError();
1585    }
1586
1587    public void glFlush() {
1588        begin("glFlush");
1589        end();
1590
1591        mgl.glFlush();
1592        checkError();
1593    }
1594
1595    public void glFogf(int pname, float param) {
1596        begin("glFogf");
1597        arg("pname", pname);
1598        arg("param", param);
1599        end();
1600
1601        mgl.glFogf(pname, param);
1602        checkError();
1603    }
1604
1605    public void glFogfv(int pname, float[] params, int offset) {
1606        begin("glFogfv");
1607        arg("pname", getFogPName(pname));
1608        arg("params", getFogParamCount(pname), params, offset);
1609        arg("offset", offset);
1610        end();
1611
1612        mgl.glFogfv(pname, params, offset);
1613        checkError();
1614    }
1615
1616    public void glFogfv(int pname, FloatBuffer params) {
1617        begin("glFogfv");
1618        arg("pname", getFogPName(pname));
1619        arg("params", getFogParamCount(pname), params);
1620        end();
1621
1622        mgl.glFogfv(pname, params);
1623        checkError();
1624    }
1625
1626    public void glFogx(int pname, int param) {
1627        begin("glFogx");
1628        arg("pname", getFogPName(pname));
1629        arg("param", param);
1630        end();
1631
1632        mgl.glFogx(pname, param);
1633        checkError();
1634    }
1635
1636    public void glFogxv(int pname, int[] params, int offset) {
1637        begin("glFogxv");
1638        arg("pname", getFogPName(pname));
1639        arg("params", getFogParamCount(pname), params, offset);
1640        arg("offset", offset);
1641        end();
1642
1643        mgl.glFogxv(pname, params, offset);
1644        checkError();
1645    }
1646
1647    public void glFogxv(int pname, IntBuffer params) {
1648        begin("glFogxv");
1649        arg("pname", getFogPName(pname));
1650        arg("params", getFogParamCount(pname), params);
1651        end();
1652
1653        mgl.glFogxv(pname, params);
1654        checkError();
1655    }
1656
1657    public void glFrontFace(int mode) {
1658        begin("glFrontFace");
1659        arg("mode", mode);
1660        end();
1661
1662        mgl.glFrontFace(mode);
1663        checkError();
1664    }
1665
1666    public void glFrustumf(float left, float right, float bottom, float top,
1667            float near, float far) {
1668        begin("glFrustumf");
1669        arg("left", left);
1670        arg("right", right);
1671        arg("bottom", bottom);
1672        arg("top", top);
1673        arg("near", near);
1674        arg("far", far);
1675        end();
1676
1677        mgl.glFrustumf(left, right, bottom, top, near, far);
1678        checkError();
1679    }
1680
1681    public void glFrustumx(int left, int right, int bottom, int top, int near,
1682            int far) {
1683        begin("glFrustumx");
1684        arg("left", left);
1685        arg("right", right);
1686        arg("bottom", bottom);
1687        arg("top", top);
1688        arg("near", near);
1689        arg("far", far);
1690        end();
1691
1692        mgl.glFrustumx(left, right, bottom, top, near, far);
1693        checkError();
1694    }
1695
1696    public void glGenTextures(int n, int[] textures, int offset) {
1697        begin("glGenTextures");
1698        arg("n", n);
1699        arg("textures", Arrays.toString(textures));
1700        arg("offset", offset);
1701
1702        mgl.glGenTextures(n, textures, offset);
1703
1704        returns(toString(n, FORMAT_INT, textures, offset));
1705
1706        checkError();
1707    }
1708
1709    public void glGenTextures(int n, IntBuffer textures) {
1710        begin("glGenTextures");
1711        arg("n", n);
1712        arg("textures", textures.toString());
1713
1714        mgl.glGenTextures(n, textures);
1715
1716        returns(toString(n, FORMAT_INT, textures));
1717
1718        checkError();
1719    }
1720
1721    public int glGetError() {
1722        begin("glGetError");
1723
1724        int result = mgl.glGetError();
1725
1726        returns(result);
1727
1728        return result;
1729    }
1730
1731    public void glGetIntegerv(int pname, int[] params, int offset) {
1732        begin("glGetIntegerv");
1733        arg("pname", getIntegerStateName(pname));
1734        arg("params", Arrays.toString(params));
1735        arg("offset", offset);
1736
1737        mgl.glGetIntegerv(pname, params, offset);
1738
1739        returns(toString(getIntegerStateSize(pname),
1740                getIntegerStateFormat(pname), params, offset));
1741
1742        checkError();
1743    }
1744
1745    public void glGetIntegerv(int pname, IntBuffer params) {
1746        begin("glGetIntegerv");
1747        arg("pname", getIntegerStateName(pname));
1748        arg("params", params.toString());
1749
1750        mgl.glGetIntegerv(pname, params);
1751
1752        returns(toString(getIntegerStateSize(pname),
1753                getIntegerStateFormat(pname), params));
1754
1755        checkError();
1756    }
1757
1758    public String glGetString(int name) {
1759        begin("glGetString");
1760        arg("name", name);
1761
1762        String result = mgl.glGetString(name);
1763
1764        returns(result);
1765
1766        checkError();
1767        return result;
1768    }
1769
1770    public void glHint(int target, int mode) {
1771        begin("glHint");
1772        arg("target", getHintTarget(target));
1773        arg("mode", getHintMode(mode));
1774        end();
1775
1776        mgl.glHint(target, mode);
1777        checkError();
1778    }
1779
1780    public void glLightModelf(int pname, float param) {
1781        begin("glLightModelf");
1782        arg("pname", getLightModelPName(pname));
1783        arg("param", param);
1784        end();
1785
1786        mgl.glLightModelf(pname, param);
1787        checkError();
1788    }
1789
1790    public void glLightModelfv(int pname, float[] params, int offset) {
1791        begin("glLightModelfv");
1792        arg("pname", getLightModelPName(pname));
1793        arg("params", getLightModelParamCount(pname), params, offset);
1794        arg("offset", offset);
1795        end();
1796
1797        mgl.glLightModelfv(pname, params, offset);
1798        checkError();
1799    }
1800
1801    public void glLightModelfv(int pname, FloatBuffer params) {
1802        begin("glLightModelfv");
1803        arg("pname", getLightModelPName(pname));
1804        arg("params", getLightModelParamCount(pname), params);
1805        end();
1806
1807        mgl.glLightModelfv(pname, params);
1808        checkError();
1809    }
1810
1811    public void glLightModelx(int pname, int param) {
1812        begin("glLightModelx");
1813        arg("pname", getLightModelPName(pname));
1814        arg("param", param);
1815        end();
1816
1817        mgl.glLightModelx(pname, param);
1818        checkError();
1819    }
1820
1821    public void glLightModelxv(int pname, int[] params, int offset) {
1822        begin("glLightModelxv");
1823        arg("pname", getLightModelPName(pname));
1824        arg("params", getLightModelParamCount(pname), params, offset);
1825        arg("offset", offset);
1826        end();
1827
1828        mgl.glLightModelxv(pname, params, offset);
1829        checkError();
1830    }
1831
1832    public void glLightModelxv(int pname, IntBuffer params) {
1833        begin("glLightModelfv");
1834        arg("pname", getLightModelPName(pname));
1835        arg("params", getLightModelParamCount(pname), params);
1836        end();
1837
1838        mgl.glLightModelxv(pname, params);
1839        checkError();
1840    }
1841
1842    public void glLightf(int light, int pname, float param) {
1843        begin("glLightf");
1844        arg("light", getLightName(light));
1845        arg("pname", getLightPName(pname));
1846        arg("param", param);
1847        end();
1848
1849        mgl.glLightf(light, pname, param);
1850        checkError();
1851    }
1852
1853    public void glLightfv(int light, int pname, float[] params, int offset) {
1854        begin("glLightfv");
1855        arg("light", getLightName(light));
1856        arg("pname", getLightPName(pname));
1857        arg("params", getLightParamCount(pname), params, offset);
1858        arg("offset", offset);
1859        end();
1860
1861        mgl.glLightfv(light, pname, params, offset);
1862        checkError();
1863    }
1864
1865    public void glLightfv(int light, int pname, FloatBuffer params) {
1866        begin("glLightfv");
1867        arg("light", getLightName(light));
1868        arg("pname", getLightPName(pname));
1869        arg("params", getLightParamCount(pname), params);
1870        end();
1871
1872        mgl.glLightfv(light, pname, params);
1873        checkError();
1874    }
1875
1876    public void glLightx(int light, int pname, int param) {
1877        begin("glLightx");
1878        arg("light", getLightName(light));
1879        arg("pname", getLightPName(pname));
1880        arg("param", param);
1881        end();
1882
1883        mgl.glLightx(light, pname, param);
1884        checkError();
1885    }
1886
1887    public void glLightxv(int light, int pname, int[] params, int offset) {
1888        begin("glLightxv");
1889        arg("light", getLightName(light));
1890        arg("pname", getLightPName(pname));
1891        arg("params", getLightParamCount(pname), params, offset);
1892        arg("offset", offset);
1893        end();
1894
1895        mgl.glLightxv(light, pname, params, offset);
1896        checkError();
1897    }
1898
1899    public void glLightxv(int light, int pname, IntBuffer params) {
1900        begin("glLightxv");
1901        arg("light", getLightName(light));
1902        arg("pname", getLightPName(pname));
1903        arg("params", getLightParamCount(pname), params);
1904        end();
1905
1906        mgl.glLightxv(light, pname, params);
1907        checkError();
1908    }
1909
1910    public void glLineWidth(float width) {
1911        begin("glLineWidth");
1912        arg("width", width);
1913        end();
1914
1915        mgl.glLineWidth(width);
1916        checkError();
1917    }
1918
1919    public void glLineWidthx(int width) {
1920        begin("glLineWidthx");
1921        arg("width", width);
1922        end();
1923
1924        mgl.glLineWidthx(width);
1925        checkError();
1926    }
1927
1928    public void glLoadIdentity() {
1929        begin("glLoadIdentity");
1930        end();
1931
1932        mgl.glLoadIdentity();
1933        checkError();
1934    }
1935
1936    public void glLoadMatrixf(float[] m, int offset) {
1937        begin("glLoadMatrixf");
1938        arg("m", 16, m, offset);
1939        arg("offset", offset);
1940        end();
1941
1942        mgl.glLoadMatrixf(m, offset);
1943        checkError();
1944    }
1945
1946    public void glLoadMatrixf(FloatBuffer m) {
1947        begin("glLoadMatrixf");
1948        arg("m", 16, m);
1949        end();
1950
1951        mgl.glLoadMatrixf(m);
1952        checkError();
1953    }
1954
1955    public void glLoadMatrixx(int[] m, int offset) {
1956        begin("glLoadMatrixx");
1957        arg("m", 16, m, offset);
1958        arg("offset", offset);
1959        end();
1960
1961        mgl.glLoadMatrixx(m, offset);
1962        checkError();
1963    }
1964
1965    public void glLoadMatrixx(IntBuffer m) {
1966        begin("glLoadMatrixx");
1967        arg("m", 16, m);
1968        end();
1969
1970        mgl.glLoadMatrixx(m);
1971        checkError();
1972    }
1973
1974    public void glLogicOp(int opcode) {
1975        begin("glLogicOp");
1976        arg("opcode", opcode);
1977        end();
1978
1979        mgl.glLogicOp(opcode);
1980        checkError();
1981    }
1982
1983    public void glMaterialf(int face, int pname, float param) {
1984        begin("glMaterialf");
1985        arg("face", getFaceName(face));
1986        arg("pname", getMaterialPName(pname));
1987        arg("param", param);
1988        end();
1989
1990        mgl.glMaterialf(face, pname, param);
1991        checkError();
1992    }
1993
1994    public void glMaterialfv(int face, int pname, float[] params, int offset) {
1995        begin("glMaterialfv");
1996        arg("face", getFaceName(face));
1997        arg("pname", getMaterialPName(pname));
1998        arg("params", getMaterialParamCount(pname), params, offset);
1999        arg("offset", offset);
2000        end();
2001
2002        mgl.glMaterialfv(face, pname, params, offset);
2003        checkError();
2004    }
2005
2006    public void glMaterialfv(int face, int pname, FloatBuffer params) {
2007        begin("glMaterialfv");
2008        arg("face", getFaceName(face));
2009        arg("pname", getMaterialPName(pname));
2010        arg("params", getMaterialParamCount(pname), params);
2011        end();
2012
2013        mgl.glMaterialfv(face, pname, params);
2014        checkError();
2015    }
2016
2017    public void glMaterialx(int face, int pname, int param) {
2018        begin("glMaterialx");
2019        arg("face", getFaceName(face));
2020        arg("pname", getMaterialPName(pname));
2021        arg("param", param);
2022        end();
2023
2024        mgl.glMaterialx(face, pname, param);
2025        checkError();
2026    }
2027
2028    public void glMaterialxv(int face, int pname, int[] params, int offset) {
2029        begin("glMaterialxv");
2030        arg("face", getFaceName(face));
2031        arg("pname", getMaterialPName(pname));
2032        arg("params", getMaterialParamCount(pname), params, offset);
2033        arg("offset", offset);
2034        end();
2035
2036        mgl.glMaterialxv(face, pname, params, offset);
2037        checkError();
2038    }
2039
2040    public void glMaterialxv(int face, int pname, IntBuffer params) {
2041        begin("glMaterialxv");
2042        arg("face", getFaceName(face));
2043        arg("pname", getMaterialPName(pname));
2044        arg("params", getMaterialParamCount(pname), params);
2045        end();
2046
2047        mgl.glMaterialxv(face, pname, params);
2048        checkError();
2049    }
2050
2051    public void glMatrixMode(int mode) {
2052        begin("glMatrixMode");
2053        arg("mode", getMatrixMode(mode));
2054        end();
2055
2056        mgl.glMatrixMode(mode);
2057        checkError();
2058    }
2059
2060    public void glMultMatrixf(float[] m, int offset) {
2061        begin("glMultMatrixf");
2062        arg("m", 16, m, offset);
2063        arg("offset", offset);
2064        end();
2065
2066        mgl.glMultMatrixf(m, offset);
2067        checkError();
2068    }
2069
2070    public void glMultMatrixf(FloatBuffer m) {
2071        begin("glMultMatrixf");
2072        arg("m", 16, m);
2073        end();
2074
2075        mgl.glMultMatrixf(m);
2076        checkError();
2077    }
2078
2079    public void glMultMatrixx(int[] m, int offset) {
2080        begin("glMultMatrixx");
2081        arg("m", 16, m, offset);
2082        arg("offset", offset);
2083        end();
2084
2085        mgl.glMultMatrixx(m, offset);
2086        checkError();
2087    }
2088
2089    public void glMultMatrixx(IntBuffer m) {
2090        begin("glMultMatrixx");
2091        arg("m", 16, m);
2092        end();
2093
2094        mgl.glMultMatrixx(m);
2095        checkError();
2096    }
2097
2098    public void glMultiTexCoord4f(int target, float s, float t, float r, float q) {
2099        begin("glMultiTexCoord4f");
2100        arg("target", target);
2101        arg("s", s);
2102        arg("t", t);
2103        arg("r", r);
2104        arg("q", q);
2105        end();
2106
2107        mgl.glMultiTexCoord4f(target, s, t, r, q);
2108        checkError();
2109    }
2110
2111    public void glMultiTexCoord4x(int target, int s, int t, int r, int q) {
2112        begin("glMultiTexCoord4x");
2113        arg("target", target);
2114        arg("s", s);
2115        arg("t", t);
2116        arg("r", r);
2117        arg("q", q);
2118        end();
2119
2120        mgl.glMultiTexCoord4x(target, s, t, r, q);
2121        checkError();
2122    }
2123
2124    public void glNormal3f(float nx, float ny, float nz) {
2125        begin("glNormal3f");
2126        arg("nx", nx);
2127        arg("ny", ny);
2128        arg("nz", nz);
2129        end();
2130
2131        mgl.glNormal3f(nx, ny, nz);
2132        checkError();
2133    }
2134
2135    public void glNormal3x(int nx, int ny, int nz) {
2136        begin("glNormal3x");
2137        arg("nx", nx);
2138        arg("ny", ny);
2139        arg("nz", nz);
2140        end();
2141
2142        mgl.glNormal3x(nx, ny, nz);
2143        checkError();
2144    }
2145
2146    public void glNormalPointer(int type, int stride, Buffer pointer) {
2147        begin("glNormalPointer");
2148        arg("type", type);
2149        arg("stride", stride);
2150        arg("pointer", pointer.toString());
2151        end();
2152        mNormalPointer = new PointerInfo(3, type, stride, pointer);
2153
2154        mgl.glNormalPointer(type, stride, pointer);
2155        checkError();
2156    }
2157
2158    public void glOrthof(float left, float right, float bottom, float top,
2159            float near, float far) {
2160        begin("glOrthof");
2161        arg("left", left);
2162        arg("right", right);
2163        arg("bottom", bottom);
2164        arg("top", top);
2165        arg("near", near);
2166        arg("far", far);
2167        end();
2168
2169        mgl.glOrthof(left, right, bottom, top, near, far);
2170        checkError();
2171    }
2172
2173    public void glOrthox(int left, int right, int bottom, int top, int near,
2174            int far) {
2175        begin("glOrthox");
2176        arg("left", left);
2177        arg("right", right);
2178        arg("bottom", bottom);
2179        arg("top", top);
2180        arg("near", near);
2181        arg("far", far);
2182        end();
2183
2184        mgl.glOrthox(left, right, bottom, top, near, far);
2185        checkError();
2186    }
2187
2188    public void glPixelStorei(int pname, int param) {
2189        begin("glPixelStorei");
2190        arg("pname", pname);
2191        arg("param", param);
2192        end();
2193
2194        mgl.glPixelStorei(pname, param);
2195        checkError();
2196    }
2197
2198    public void glPointSize(float size) {
2199        begin("glPointSize");
2200        arg("size", size);
2201        end();
2202
2203        mgl.glPointSize(size);
2204        checkError();
2205    }
2206
2207    public void glPointSizex(int size) {
2208        begin("glPointSizex");
2209        arg("size", size);
2210        end();
2211
2212        mgl.glPointSizex(size);
2213        checkError();
2214    }
2215
2216    public void glPolygonOffset(float factor, float units) {
2217        begin("glPolygonOffset");
2218        arg("factor", factor);
2219        arg("units", units);
2220        end();
2221        mgl.glPolygonOffset(factor, units);
2222        checkError();
2223    }
2224
2225    public void glPolygonOffsetx(int factor, int units) {
2226        begin("glPolygonOffsetx");
2227        arg("factor", factor);
2228        arg("units", units);
2229        end();
2230
2231        mgl.glPolygonOffsetx(factor, units);
2232        checkError();
2233    }
2234
2235    public void glPopMatrix() {
2236        begin("glPopMatrix");
2237        end();
2238
2239        mgl.glPopMatrix();
2240        checkError();
2241    }
2242
2243    public void glPushMatrix() {
2244        begin("glPushMatrix");
2245        end();
2246
2247        mgl.glPushMatrix();
2248        checkError();
2249    }
2250
2251    public void glReadPixels(int x, int y, int width, int height, int format,
2252            int type, Buffer pixels) {
2253        begin("glReadPixels");
2254        arg("x", x);
2255        arg("y", y);
2256        arg("width", width);
2257        arg("height", height);
2258        arg("format", format);
2259        arg("type", type);
2260        arg("pixels", pixels.toString());
2261        end();
2262
2263        mgl.glReadPixels(x, y, width, height, format, type, pixels);
2264        checkError();
2265    }
2266
2267    public void glRotatef(float angle, float x, float y, float z) {
2268        begin("glRotatef");
2269        arg("angle", angle);
2270        arg("x", x);
2271        arg("y", y);
2272        arg("z", z);
2273        end();
2274
2275        mgl.glRotatef(angle, x, y, z);
2276        checkError();
2277    }
2278
2279    public void glRotatex(int angle, int x, int y, int z) {
2280        begin("glRotatex");
2281        arg("angle", angle);
2282        arg("x", x);
2283        arg("y", y);
2284        arg("z", z);
2285        end();
2286
2287        mgl.glRotatex(angle, x, y, z);
2288        checkError();
2289    }
2290
2291    public void glSampleCoverage(float value, boolean invert) {
2292        begin("glSampleCoveragex");
2293        arg("value", value);
2294        arg("invert", invert);
2295        end();
2296
2297        mgl.glSampleCoverage(value, invert);
2298        checkError();
2299    }
2300
2301    public void glSampleCoveragex(int value, boolean invert) {
2302        begin("glSampleCoveragex");
2303        arg("value", value);
2304        arg("invert", invert);
2305        end();
2306
2307        mgl.glSampleCoveragex(value, invert);
2308        checkError();
2309    }
2310
2311    public void glScalef(float x, float y, float z) {
2312        begin("glScalef");
2313        arg("x", x);
2314        arg("y", y);
2315        arg("z", z);
2316        end();
2317
2318        mgl.glScalef(x, y, z);
2319        checkError();
2320    }
2321
2322    public void glScalex(int x, int y, int z) {
2323        begin("glScalex");
2324        arg("x", x);
2325        arg("y", y);
2326        arg("z", z);
2327        end();
2328
2329        mgl.glScalex(x, y, z);
2330        checkError();
2331    }
2332
2333    public void glScissor(int x, int y, int width, int height) {
2334        begin("glScissor");
2335        arg("x", x);
2336        arg("y", y);
2337        arg("width", width);
2338        arg("height", height);
2339        end();
2340
2341        mgl.glScissor(x, y, width, height);
2342        checkError();
2343    }
2344
2345    public void glShadeModel(int mode) {
2346        begin("glShadeModel");
2347        arg("mode", getShadeModel(mode));
2348        end();
2349
2350        mgl.glShadeModel(mode);
2351        checkError();
2352    }
2353
2354    public void glStencilFunc(int func, int ref, int mask) {
2355        begin("glStencilFunc");
2356        arg("func", func);
2357        arg("ref", ref);
2358        arg("mask", mask);
2359        end();
2360
2361        mgl.glStencilFunc(func, ref, mask);
2362        checkError();
2363    }
2364
2365    public void glStencilMask(int mask) {
2366        begin("glStencilMask");
2367        arg("mask", mask);
2368        end();
2369
2370        mgl.glStencilMask(mask);
2371        checkError();
2372    }
2373
2374    public void glStencilOp(int fail, int zfail, int zpass) {
2375        begin("glStencilOp");
2376        arg("fail", fail);
2377        arg("zfail", zfail);
2378        arg("zpass", zpass);
2379        end();
2380
2381        mgl.glStencilOp(fail, zfail, zpass);
2382        checkError();
2383    }
2384
2385    public void glTexCoordPointer(int size, int type, int stride, Buffer pointer) {
2386        begin("glTexCoordPointer");
2387        argPointer(size, type, stride, pointer);
2388        end();
2389        mTexCoordPointer = new PointerInfo(size, type, stride, pointer);
2390
2391        mgl.glTexCoordPointer(size, type, stride, pointer);
2392        checkError();
2393    }
2394
2395    public void glTexEnvf(int target, int pname, float param) {
2396        begin("glTexEnvf");
2397        arg("target", getTextureEnvTarget(target));
2398        arg("pname", getTextureEnvPName(pname));
2399        arg("param", getTextureEnvParamName(param));
2400        end();
2401
2402        mgl.glTexEnvf(target, pname, param);
2403        checkError();
2404    }
2405
2406    public void glTexEnvfv(int target, int pname, float[] params, int offset) {
2407        begin("glTexEnvfv");
2408        arg("target", getTextureEnvTarget(target));
2409        arg("pname", getTextureEnvPName(pname));
2410        arg("params", getTextureEnvParamCount(pname), params, offset);
2411        arg("offset", offset);
2412        end();
2413
2414        mgl.glTexEnvfv(target, pname, params, offset);
2415        checkError();
2416    }
2417
2418    public void glTexEnvfv(int target, int pname, FloatBuffer params) {
2419        begin("glTexEnvfv");
2420        arg("target", getTextureEnvTarget(target));
2421        arg("pname", getTextureEnvPName(pname));
2422        arg("params", getTextureEnvParamCount(pname), params);
2423        end();
2424
2425        mgl.glTexEnvfv(target, pname, params);
2426        checkError();
2427    }
2428
2429    public void glTexEnvx(int target, int pname, int param) {
2430        begin("glTexEnvx");
2431        arg("target", getTextureEnvTarget(target));
2432        arg("pname", getTextureEnvPName(pname));
2433        arg("param", param);
2434        end();
2435
2436        mgl.glTexEnvx(target, pname, param);
2437        checkError();
2438    }
2439
2440    public void glTexEnvxv(int target, int pname, int[] params, int offset) {
2441        begin("glTexEnvxv");
2442        arg("target", getTextureEnvTarget(target));
2443        arg("pname", getTextureEnvPName(pname));
2444        arg("params", getTextureEnvParamCount(pname), params, offset);
2445        arg("offset", offset);
2446        end();
2447
2448        mgl.glTexEnvxv(target, pname, params, offset);
2449        checkError();
2450    }
2451
2452    public void glTexEnvxv(int target, int pname, IntBuffer params) {
2453        begin("glTexEnvxv");
2454        arg("target", getTextureEnvTarget(target));
2455        arg("pname", getTextureEnvPName(pname));
2456        arg("params", getTextureEnvParamCount(pname), params);
2457        end();
2458
2459        mgl.glTexEnvxv(target, pname, params);
2460        checkError();
2461    }
2462
2463    public void glTexImage2D(int target, int level, int internalformat,
2464            int width, int height, int border, int format, int type,
2465            Buffer pixels) {
2466        begin("glTexImage2D");
2467        arg("target", target);
2468        arg("level", level);
2469        arg("internalformat", internalformat);
2470        arg("width", width);
2471        arg("height", height);
2472        arg("border", border);
2473        arg("format", format);
2474        arg("type", type);
2475        arg("pixels", pixels.toString());
2476        end();
2477
2478        mgl.glTexImage2D(target, level, internalformat, width, height, border,
2479                format, type, pixels);
2480        checkError();
2481    }
2482
2483    public void glTexParameterf(int target, int pname, float param) {
2484        begin("glTexParameterf");
2485        arg("target", getTextureTarget(target));
2486        arg("pname", getTexturePName(pname));
2487        arg("param", getTextureParamName(param));
2488        end();
2489
2490        mgl.glTexParameterf(target, pname, param);
2491        checkError();
2492    }
2493
2494    public void glTexParameterx(int target, int pname, int param) {
2495        begin("glTexParameterx");
2496        arg("target", getTextureTarget(target));
2497        arg("pname", getTexturePName(pname));
2498        arg("param", param);
2499        end();
2500
2501        mgl.glTexParameterx(target, pname, param);
2502        checkError();
2503    }
2504
2505    public void glTexParameteriv(int target, int pname, int[] params, int offset) {
2506        begin("glTexParameteriv");
2507        arg("target", getTextureTarget(target));
2508        arg("pname", getTexturePName(pname));
2509        arg("params", 4, params, offset);
2510        end();
2511
2512        mgl11.glTexParameteriv(target, pname, params, offset);
2513        checkError();
2514    }
2515
2516    public void glTexParameteriv(int target, int pname, IntBuffer params) {
2517        begin("glTexParameteriv");
2518        arg("target", getTextureTarget(target));
2519        arg("pname", getTexturePName(pname));
2520        arg("params", 4, params);
2521        end();
2522
2523        mgl11.glTexParameteriv(target, pname, params);
2524        checkError();
2525    }
2526
2527    public void glTexSubImage2D(int target, int level, int xoffset,
2528            int yoffset, int width, int height, int format, int type,
2529            Buffer pixels) {
2530        begin("glTexSubImage2D");
2531        arg("target", getTextureTarget(target));
2532        arg("level", level);
2533        arg("xoffset", xoffset);
2534        arg("yoffset", yoffset);
2535        arg("width", width);
2536        arg("height", height);
2537        arg("format", format);
2538        arg("type", type);
2539        arg("pixels", pixels.toString());
2540        end();
2541        mgl.glTexSubImage2D(target, level, xoffset, yoffset, width, height,
2542                format, type, pixels);
2543        checkError();
2544    }
2545
2546    public void glTranslatef(float x, float y, float z) {
2547        begin("glTranslatef");
2548        arg("x", x);
2549        arg("y", y);
2550        arg("z", z);
2551        end();
2552        mgl.glTranslatef(x, y, z);
2553        checkError();
2554    }
2555
2556    public void glTranslatex(int x, int y, int z) {
2557        begin("glTranslatex");
2558        arg("x", x);
2559        arg("y", y);
2560        arg("z", z);
2561        end();
2562        mgl.glTranslatex(x, y, z);
2563        checkError();
2564    }
2565
2566    public void glVertexPointer(int size, int type, int stride, Buffer pointer) {
2567        begin("glVertexPointer");
2568        argPointer(size, type, stride, pointer);
2569        end();
2570        mVertexPointer = new PointerInfo(size, type, stride, pointer);
2571        mgl.glVertexPointer(size, type, stride, pointer);
2572        checkError();
2573    }
2574
2575    public void glViewport(int x, int y, int width, int height) {
2576        begin("glViewport");
2577        arg("x", x);
2578        arg("y", y);
2579        arg("width", width);
2580        arg("height", height);
2581        end();
2582        mgl.glViewport(x, y, width, height);
2583        checkError();
2584    }
2585
2586    public void glClipPlanef(int plane, float[] equation, int offset) {
2587        begin("glClipPlanef");
2588        arg("plane", plane);
2589        arg("equation", 4, equation, offset);
2590        arg("offset", offset);
2591        end();
2592        mgl11.glClipPlanef(plane, equation, offset);
2593        checkError();
2594    }
2595
2596    public void glClipPlanef(int plane, FloatBuffer equation) {
2597        begin("glClipPlanef");
2598        arg("plane", plane);
2599        arg("equation", 4, equation);
2600        end();
2601        mgl11.glClipPlanef(plane, equation);
2602        checkError();
2603    }
2604
2605    public void glClipPlanex(int plane, int[] equation, int offset) {
2606        begin("glClipPlanex");
2607        arg("plane", plane);
2608        arg("equation", 4, equation, offset);
2609        arg("offset", offset);
2610        end();
2611        mgl11.glClipPlanex(plane, equation, offset);
2612        checkError();
2613    }
2614
2615    public void glClipPlanex(int plane, IntBuffer equation) {
2616        begin("glClipPlanef");
2617        arg("plane", plane);
2618        arg("equation", 4, equation);
2619        end();
2620        mgl11.glClipPlanex(plane, equation);
2621        checkError();
2622    }
2623
2624    // Draw Texture Extension
2625
2626    public void glDrawTexfOES(float x, float y, float z,
2627        float width, float height) {
2628        begin("glDrawTexfOES");
2629        arg("x", x);
2630        arg("y", y);
2631        arg("z", z);
2632        arg("width", width);
2633        arg("height", height);
2634        end();
2635        mgl11Ext.glDrawTexfOES(x, y, z, width, height);
2636        checkError();
2637    }
2638
2639    public void glDrawTexfvOES(float[] coords, int offset) {
2640        begin("glDrawTexfvOES");
2641        arg("coords", 5, coords, offset);
2642        arg("offset", offset);
2643        end();
2644        mgl11Ext.glDrawTexfvOES(coords, offset);
2645        checkError();
2646    }
2647
2648    public void glDrawTexfvOES(FloatBuffer coords) {
2649        begin("glDrawTexfvOES");
2650        arg("coords", 5, coords);
2651        end();
2652        mgl11Ext.glDrawTexfvOES(coords);
2653        checkError();
2654    }
2655
2656    public void glDrawTexiOES(int x, int y, int z, int width, int height) {
2657        begin("glDrawTexiOES");
2658        arg("x", x);
2659        arg("y", y);
2660        arg("z", z);
2661        arg("width", width);
2662        arg("height", height);
2663        end();
2664        mgl11Ext.glDrawTexiOES(x, y, z, width, height);
2665        checkError();
2666    }
2667
2668    public void glDrawTexivOES(int[] coords, int offset) {
2669        begin("glDrawTexivOES");
2670        arg("coords", 5, coords, offset);
2671        arg("offset", offset);
2672        end();
2673        mgl11Ext.glDrawTexivOES(coords, offset);
2674        checkError();
2675    }
2676
2677    public void glDrawTexivOES(IntBuffer coords) {
2678        begin("glDrawTexivOES");
2679        arg("coords", 5, coords);
2680        end();
2681        mgl11Ext.glDrawTexivOES(coords);
2682        checkError();
2683    }
2684
2685    public void glDrawTexsOES(short x, short y, short z,
2686        short width, short height) {
2687        begin("glDrawTexsOES");
2688        arg("x", x);
2689        arg("y", y);
2690        arg("z", z);
2691        arg("width", width);
2692        arg("height", height);
2693        end();
2694        mgl11Ext.glDrawTexsOES(x, y, z, width, height);
2695        checkError();
2696    }
2697
2698    public void glDrawTexsvOES(short[] coords, int offset) {
2699        begin("glDrawTexsvOES");
2700        arg("coords", 5, coords, offset);
2701        arg("offset", offset);
2702        end();
2703        mgl11Ext.glDrawTexsvOES(coords, offset);
2704        checkError();
2705    }
2706
2707    public void glDrawTexsvOES(ShortBuffer coords) {
2708        begin("glDrawTexsvOES");
2709        arg("coords", 5, coords);
2710        end();
2711        mgl11Ext.glDrawTexsvOES(coords);
2712        checkError();
2713    }
2714
2715    public void glDrawTexxOES(int x, int y, int z, int width, int height) {
2716        begin("glDrawTexxOES");
2717        arg("x", x);
2718        arg("y", y);
2719        arg("z", z);
2720        arg("width", width);
2721        arg("height", height);
2722        end();
2723        mgl11Ext.glDrawTexxOES(x, y, z, width, height);
2724        checkError();
2725    }
2726
2727    public void glDrawTexxvOES(int[] coords, int offset) {
2728        begin("glDrawTexxvOES");
2729        arg("coords", 5, coords, offset);
2730        arg("offset", offset);
2731        end();
2732        mgl11Ext.glDrawTexxvOES(coords, offset);
2733        checkError();
2734    }
2735
2736    public void glDrawTexxvOES(IntBuffer coords) {
2737        begin("glDrawTexxvOES");
2738        arg("coords", 5, coords);
2739        end();
2740        mgl11Ext.glDrawTexxvOES(coords);
2741        checkError();
2742    }
2743
2744    public int glQueryMatrixxOES(int[] mantissa, int mantissaOffset,
2745        int[] exponent, int exponentOffset) {
2746        begin("glQueryMatrixxOES");
2747        arg("mantissa", Arrays.toString(mantissa));
2748        arg("exponent", Arrays.toString(exponent));
2749        end();
2750        int valid = mgl10Ext.glQueryMatrixxOES(mantissa, mantissaOffset,
2751            exponent, exponentOffset);
2752        returns(toString(16, FORMAT_FIXED, mantissa, mantissaOffset));
2753        returns(toString(16, FORMAT_INT, exponent, exponentOffset));
2754        checkError();
2755        return valid;
2756    }
2757
2758    public int glQueryMatrixxOES(IntBuffer mantissa, IntBuffer exponent) {
2759        begin("glQueryMatrixxOES");
2760        arg("mantissa", mantissa.toString());
2761        arg("exponent", exponent.toString());
2762        end();
2763        int valid = mgl10Ext.glQueryMatrixxOES(mantissa, exponent);
2764        returns(toString(16, FORMAT_FIXED, mantissa));
2765        returns(toString(16, FORMAT_INT, exponent));
2766        checkError();
2767        return valid;
2768    }
2769
2770    // Unsupported GL11 methods
2771
2772    public void glBindBuffer(int target, int buffer) {
2773        throw new UnsupportedOperationException();
2774    }
2775
2776    public void glBufferData(int target, int size, Buffer data, int usage) {
2777        throw new UnsupportedOperationException();
2778    }
2779
2780    public void glBufferSubData(int target, int offset, int size, Buffer data) {
2781        throw new UnsupportedOperationException();
2782    }
2783
2784    public void glColor4ub(byte red, byte green, byte blue, byte alpha) {
2785        throw new UnsupportedOperationException();
2786    }
2787
2788    public void glDeleteBuffers(int n, int[] buffers, int offset) {
2789        throw new UnsupportedOperationException();
2790    }
2791
2792    public void glDeleteBuffers(int n, IntBuffer buffers) {
2793        throw new UnsupportedOperationException();
2794    }
2795
2796    public void glGenBuffers(int n, int[] buffers, int offset) {
2797        throw new UnsupportedOperationException();
2798    }
2799
2800    public void glGenBuffers(int n, IntBuffer buffers) {
2801        throw new UnsupportedOperationException();
2802    }
2803
2804    public void glGetBooleanv(int pname, boolean[] params, int offset) {
2805        throw new UnsupportedOperationException();
2806    }
2807
2808    public void glGetBooleanv(int pname, IntBuffer params) {
2809        throw new UnsupportedOperationException();
2810    }
2811
2812    public void glGetBufferParameteriv(int target, int pname, int[] params, int offset) {
2813        throw new UnsupportedOperationException();
2814    }
2815
2816    public void glGetBufferParameteriv(int target, int pname, IntBuffer params) {
2817        throw new UnsupportedOperationException();
2818    }
2819
2820    public void glGetClipPlanef(int pname, float[] eqn, int offset) {
2821        throw new UnsupportedOperationException();
2822    }
2823
2824    public void glGetClipPlanef(int pname, FloatBuffer eqn) {
2825        throw new UnsupportedOperationException();
2826    }
2827
2828    public void glGetClipPlanex(int pname, int[] eqn, int offset) {
2829        throw new UnsupportedOperationException();
2830    }
2831
2832    public void glGetClipPlanex(int pname, IntBuffer eqn) {
2833        throw new UnsupportedOperationException();
2834    }
2835
2836    public void glGetFixedv(int pname, int[] params, int offset) {
2837        throw new UnsupportedOperationException();
2838    }
2839
2840    public void glGetFixedv(int pname, IntBuffer params) {
2841        throw new UnsupportedOperationException();
2842    }
2843
2844    public void glGetFloatv(int pname, float[] params, int offset) {
2845        throw new UnsupportedOperationException();
2846    }
2847
2848    public void glGetFloatv(int pname, FloatBuffer params) {
2849        throw new UnsupportedOperationException();
2850    }
2851
2852    public void glGetLightfv(int light, int pname, float[] params, int offset) {
2853        throw new UnsupportedOperationException();
2854    }
2855
2856    public void glGetLightfv(int light, int pname, FloatBuffer params) {
2857        throw new UnsupportedOperationException();
2858    }
2859
2860    public void glGetLightxv(int light, int pname, int[] params, int offset) {
2861        throw new UnsupportedOperationException();
2862    }
2863
2864    public void glGetLightxv(int light, int pname, IntBuffer params) {
2865        throw new UnsupportedOperationException();
2866    }
2867
2868    public void glGetMaterialfv(int face, int pname, float[] params, int offset) {
2869        throw new UnsupportedOperationException();
2870    }
2871
2872    public void glGetMaterialfv(int face, int pname, FloatBuffer params) {
2873        throw new UnsupportedOperationException();
2874    }
2875
2876    public void glGetMaterialxv(int face, int pname, int[] params, int offset) {
2877        throw new UnsupportedOperationException();
2878    }
2879
2880    public void glGetMaterialxv(int face, int pname, IntBuffer params) {
2881        throw new UnsupportedOperationException();
2882    }
2883
2884    public void glGetTexEnviv(int env, int pname, int[] params, int offset) {
2885        throw new UnsupportedOperationException();
2886    }
2887
2888    public void glGetTexEnviv(int env, int pname, IntBuffer params) {
2889        throw new UnsupportedOperationException();
2890    }
2891
2892    public void glGetTexEnvxv(int env, int pname, int[] params, int offset) {
2893        throw new UnsupportedOperationException();
2894    }
2895
2896    public void glGetTexEnvxv(int env, int pname, IntBuffer params) {
2897        throw new UnsupportedOperationException();
2898    }
2899
2900    public void glGetTexParameterfv(int target, int pname, float[] params, int offset) {
2901        throw new UnsupportedOperationException();
2902    }
2903
2904    public void glGetTexParameterfv(int target, int pname, FloatBuffer params) {
2905        throw new UnsupportedOperationException();
2906    }
2907
2908    public void glGetTexParameteriv(int target, int pname, int[] params, int offset) {
2909        throw new UnsupportedOperationException();
2910    }
2911
2912    public void glGetTexParameteriv(int target, int pname, IntBuffer params) {
2913        throw new UnsupportedOperationException();
2914    }
2915
2916    public void glGetTexParameterxv(int target, int pname, int[] params, int offset) {
2917        throw new UnsupportedOperationException();
2918    }
2919
2920    public void glGetTexParameterxv(int target, int pname, IntBuffer params) {
2921        throw new UnsupportedOperationException();
2922    }
2923
2924    public boolean glIsBuffer(int buffer) {
2925        throw new UnsupportedOperationException();
2926    }
2927
2928    public boolean glIsEnabled(int cap) {
2929        throw new UnsupportedOperationException();
2930    }
2931
2932    public boolean glIsTexture(int texture) {
2933        throw new UnsupportedOperationException();
2934    }
2935
2936    public void glPointParameterf(int pname, float param) {
2937        throw new UnsupportedOperationException();
2938    }
2939
2940    public void glPointParameterfv(int pname, float[] params, int offset) {
2941        throw new UnsupportedOperationException();
2942    }
2943
2944    public void glPointParameterfv(int pname, FloatBuffer params) {
2945        throw new UnsupportedOperationException();
2946    }
2947
2948    public void glPointParameterx(int pname, int param) {
2949        throw new UnsupportedOperationException();
2950    }
2951
2952    public void glPointParameterxv(int pname, int[] params, int offset) {
2953        throw new UnsupportedOperationException();
2954    }
2955
2956    public void glPointParameterxv(int pname, IntBuffer params) {
2957        throw new UnsupportedOperationException();
2958    }
2959
2960    public void glPointSizePointerOES(int type, int stride, Buffer pointer) {
2961        throw new UnsupportedOperationException();
2962    }
2963
2964    public void glTexEnvi(int target, int pname, int param) {
2965        throw new UnsupportedOperationException();
2966    }
2967
2968    public void glTexEnviv(int target, int pname, int[] params, int offset) {
2969        throw new UnsupportedOperationException();
2970    }
2971
2972    public void glTexEnviv(int target, int pname, IntBuffer params) {
2973        throw new UnsupportedOperationException();
2974    }
2975
2976    public void glTexParameterfv(int target, int pname, float[] params, int offset) {
2977        throw new UnsupportedOperationException();
2978    }
2979
2980    public void glTexParameterfv(int target, int pname, FloatBuffer params) {
2981        throw new UnsupportedOperationException();
2982    }
2983
2984    public void glTexParameteri(int target, int pname, int param) {
2985        throw new UnsupportedOperationException();
2986    }
2987
2988    public void glTexParameterxv(int target, int pname, int[] params, int offset) {
2989        throw new UnsupportedOperationException();
2990    }
2991
2992    public void glTexParameterxv(int target, int pname, IntBuffer params) {
2993        throw new UnsupportedOperationException();
2994    }
2995
2996    private class PointerInfo {
2997        /**
2998         * The number of coordinates per vertex. 1..4
2999         */
3000        public int mSize;
3001        /**
3002         * The type of each coordinate.
3003         */
3004        public int mType;
3005        /**
3006         * The byte offset between consecutive vertices. 0 means mSize *
3007         * sizeof(mType)
3008         */
3009        public int mStride;
3010        public Buffer mPointer;
3011        public ByteBuffer mTempByteBuffer; // Only valid during glDrawXXX calls
3012
3013        public PointerInfo() {
3014        }
3015
3016        public PointerInfo(int size, int type, int stride, Buffer pointer) {
3017            mSize = size;
3018            mType = type;
3019            mStride = stride;
3020            mPointer = pointer;
3021        }
3022
3023        public int sizeof(int type) {
3024            switch (type) {
3025            case GL_UNSIGNED_BYTE:
3026                return 1;
3027            case GL_BYTE:
3028                return 1;
3029            case GL_SHORT:
3030                return 2;
3031            case GL_FIXED:
3032                return 4;
3033            case GL_FLOAT:
3034                return 4;
3035            default:
3036                return 0;
3037            }
3038        }
3039
3040        public int getStride() {
3041            return mStride > 0 ? mStride : sizeof(mType) * mSize;
3042        }
3043
3044        public void bindByteBuffer() {
3045            mTempByteBuffer = mPointer == null ? null : toByteBuffer(-1, mPointer);
3046        }
3047
3048        public void unbindByteBuffer() {
3049            mTempByteBuffer = null;
3050        }
3051    }
3052
3053    private Writer mLog;
3054    private boolean mLogArgumentNames;
3055    private int mArgCount;
3056
3057    private PointerInfo mColorPointer = new PointerInfo();
3058    private PointerInfo mNormalPointer = new PointerInfo();
3059    private PointerInfo mTexCoordPointer = new PointerInfo();
3060    private PointerInfo mVertexPointer = new PointerInfo();
3061
3062    boolean mColorArrayEnabled;
3063    boolean mNormalArrayEnabled;
3064    boolean mTextureCoordArrayEnabled;
3065    boolean mVertexArrayEnabled;
3066
3067    StringBuilder mStringBuilder;
3068}
3069