0001: /*
0002: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
0003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
0004: *
0005: * This program is free software; you can redistribute it and/or
0006: * modify it under the terms of the GNU General Public License version
0007: * 2 only, as published by the Free Software Foundation.
0008: *
0009: * This program is distributed in the hope that it will be useful, but
0010: * WITHOUT ANY WARRANTY; without even the implied warranty of
0011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0012: * General Public License version 2 for more details (a copy is
0013: * included at /legal/license.txt).
0014: *
0015: * You should have received a copy of the GNU General Public License
0016: * version 2 along with this work; if not, write to the Free Software
0017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0018: * 02110-1301 USA
0019: *
0020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0021: * Clara, CA 95054 or visit www.sun.com if you need additional
0022: * information or have any questions.
0023: */
0024:
0025: package com.sun.jsr239;
0026:
0027: import javax.microedition.khronos.egl.*;
0028: import javax.microedition.khronos.opengles.*;
0029: import java.nio.*;
0030: import java.util.Hashtable;
0031:
0032: public class GL10Impl implements GL10, GL10Ext {
0033:
0034: static final boolean debugQueue = false;
0035:
0036: static final boolean DEBUG_MEM = false;
0037:
0038: static EGL10 egl = (EGL10) EGLContext.getEGL();
0039:
0040: /**
0041: * <code>context</code> is the context the GL10
0042: * is created for.
0043: */
0044: EGLContext context = null;
0045:
0046: int pixelStorePackAlignment = 4;
0047: int pixelStoreUnpackAlignment = 4;
0048:
0049: // Constants used to index gl*Pointer information tables.
0050:
0051: int VERTEX_POINTER = 0;
0052: int COLOR_POINTER = 1;
0053: int NORMAL_POINTER = 2;
0054: int TEX_COORD_POINTER = 3;
0055: int POINT_SIZE_POINTER = 4;
0056: int MATRIX_INDEX_POINTER = 5;
0057: int WEIGHT_POINTER = 6;
0058:
0059: // References to long-lived Buffers that remain part of the GL
0060: // state even after a qflush(). Indexed by *_POINTER constants,
0061: // above.
0062:
0063: Buffer[] pointerBuffer = new Buffer[7];
0064:
0065: // Parameters to gl*Pointer that affect bounds checking of
0066: // glDrawArrays and glDrawElements. Indexed by *_POINTER
0067: // constants, above.
0068:
0069: boolean[] pointerEnabled = new boolean[7];
0070: int[] pointerSize = new int[7];
0071: int[] pointerType = new int[7];
0072: int[] pointerStride = new int[7];
0073: int[] pointerOffset = new int[7];
0074: int[] pointerRemaining = new int[7];
0075:
0076: public static final int CMD_ACTIVE_TEXTURE = 1;
0077: public static final int CMD_ALPHA_FUNC = 2;
0078: public static final int CMD_ALPHA_FUNCX = 3;
0079: public static final int CMD_BIND_BUFFER = 4;
0080: public static final int CMD_BIND_TEXTURE = 5;
0081: public static final int CMD_BLEND_FUNC = 6;
0082: public static final int CMD_BUFFER_DATA = 7;
0083: public static final int CMD_BUFFER_SUB_DATA = 8;
0084: public static final int CMD_CLEAR = 9;
0085: public static final int CMD_CLEAR_COLOR = 10;
0086: public static final int CMD_CLEAR_COLORX = 11;
0087: public static final int CMD_CLEAR_DEPTHF = 12;
0088: public static final int CMD_CLEAR_DEPTHX = 13;
0089: public static final int CMD_CLEAR_STENCIL = 14;
0090: public static final int CMD_CLIENT_ACTIVE_TEXTURE = 15;
0091: public static final int CMD_CLIP_PLANEF = 16;
0092: public static final int CMD_CLIP_PLANEFB = 17;
0093: public static final int CMD_CLIP_PLANEX = 18;
0094: public static final int CMD_CLIP_PLANEXB = 19;
0095: public static final int CMD_COLOR4F = 20;
0096: public static final int CMD_COLOR4X = 21;
0097: public static final int CMD_COLOR4UB = 22;
0098: public static final int CMD_COLOR_MASK = 23;
0099: public static final int CMD_COLOR_POINTER = 24;
0100: public static final int CMD_COLOR_POINTER_VBO = 25;
0101: public static final int CMD_COMPRESSED_TEX_IMAGE_2D = 26;
0102: public static final int CMD_COMPRESSED_TEX_SUB_IMAGE_2D = 27;
0103: public static final int CMD_COPY_TEX_IMAGE_2D = 28;
0104: public static final int CMD_COPY_TEX_SUB_IMAGE_2D = 29;
0105: public static final int CMD_CULL_FACE = 30;
0106: public static final int CMD_CURRENT_PALETTE_MATRIX = 31;
0107: public static final int CMD_DELETE_BUFFERS = 32;
0108: public static final int CMD_DELETE_BUFFERSB = 33;
0109: public static final int CMD_DELETE_TEXTURES = 34;
0110: public static final int CMD_DELETE_TEXTURESB = 35;
0111: public static final int CMD_DEPTH_FUNC = 36;
0112: public static final int CMD_DEPTH_MASK = 37;
0113: public static final int CMD_DEPTH_RANGEF = 38;
0114: public static final int CMD_DEPTH_RANGEX = 39;
0115: public static final int CMD_DISABLE = 40;
0116: public static final int CMD_DISABLE_CLIENT_STATE = 41;
0117: public static final int CMD_DRAW_ARRAYS = 42;
0118: public static final int CMD_DRAW_ELEMENTSB = 43;
0119: public static final int CMD_DRAW_ELEMENTS_VBO = 44;
0120: public static final int CMD_DRAW_TEXF = 45;
0121: public static final int CMD_DRAW_TEXFB = 46;
0122: public static final int CMD_DRAW_TEXI = 47;
0123: public static final int CMD_DRAW_TEXIB = 48;
0124: public static final int CMD_DRAW_TEXS = 49;
0125: public static final int CMD_DRAW_TEXSB = 50;
0126: public static final int CMD_DRAW_TEXX = 51;
0127: public static final int CMD_DRAW_TEXXB = 52;
0128: public static final int CMD_ENABLE = 53;
0129: public static final int CMD_ENABLE_CLIENT_STATE = 54;
0130: public static final int CMD_FOGF = 55;
0131: public static final int CMD_FOGFB = 56;
0132: public static final int CMD_FOGFV = 57;
0133: public static final int CMD_FOGX = 58;
0134: public static final int CMD_FOGXB = 59;
0135: public static final int CMD_FOGXV = 60;
0136: public static final int CMD_FRONT_FACE = 61;
0137: public static final int CMD_FRUSTUMF = 62;
0138: public static final int CMD_FRUSTUMX = 63;
0139: public static final int CMD_HINT = 64;
0140: public static final int CMD_LIGHTF = 65;
0141: public static final int CMD_LIGHTFB = 66;
0142: public static final int CMD_LIGHTFV = 67;
0143: public static final int CMD_LIGHTX = 68;
0144: public static final int CMD_LIGHTXB = 69;
0145: public static final int CMD_LIGHTXV = 70;
0146: public static final int CMD_LIGHT_MODELF = 71;
0147: public static final int CMD_LIGHT_MODELFB = 72;
0148: public static final int CMD_LIGHT_MODELFV = 73;
0149: public static final int CMD_LIGHT_MODELX = 74;
0150: public static final int CMD_LIGHT_MODELXB = 75;
0151: public static final int CMD_LIGHT_MODELXV = 76;
0152: public static final int CMD_LINE_WIDTH = 77;
0153: public static final int CMD_LINE_WIDTHX = 78;
0154: public static final int CMD_LOAD_IDENTITY = 79;
0155: public static final int CMD_LOAD_MATRIXF = 80;
0156: public static final int CMD_LOAD_MATRIXFB = 81;
0157: public static final int CMD_LOAD_MATRIXX = 82;
0158: public static final int CMD_LOAD_MATRIXXB = 83;
0159: public static final int CMD_LOAD_PALETTE_FROM_MODEL_VIEW_MATRIX = 84;
0160: public static final int CMD_LOGIC_OP = 85;
0161: public static final int CMD_MATERIALF = 86;
0162: public static final int CMD_MATERIALFB = 87;
0163: public static final int CMD_MATERIALFV = 88;
0164: public static final int CMD_MATERIALX = 89;
0165: public static final int CMD_MATERIALXB = 90;
0166: public static final int CMD_MATERIALXV = 91;
0167: public static final int CMD_MATRIX_INDEX_POINTER = 92;
0168: public static final int CMD_MATRIX_INDEX_POINTER_VBO = 93;
0169: public static final int CMD_MATRIX_MODE = 94;
0170: public static final int CMD_MULTI_TEXT_COORD4F = 95;
0171: public static final int CMD_MULTI_TEXT_COORD4X = 96;
0172: public static final int CMD_MULT_MATRIXF = 97;
0173: public static final int CMD_MULT_MATRIXFB = 98;
0174: public static final int CMD_MULT_MATRIXX = 99;
0175: public static final int CMD_MULT_MATRIXXB = 100;
0176: public static final int CMD_NORMAL3F = 101;
0177: public static final int CMD_NORMAL3X = 102;
0178: public static final int CMD_NORMAL_POINTER = 103;
0179: public static final int CMD_NORMAL_POINTER_VBO = 104;
0180: public static final int CMD_ORTHOF = 105;
0181: public static final int CMD_ORTHOX = 106;
0182: public static final int CMD_PIXEL_STOREI = 107;
0183: public static final int CMD_POINT_PARAMETERF = 108;
0184: public static final int CMD_POINT_PARAMETERFB = 109;
0185: public static final int CMD_POINT_PARAMETERFV = 110;
0186: public static final int CMD_POINT_PARAMETERX = 111;
0187: public static final int CMD_POINT_PARAMETERXB = 112;
0188: public static final int CMD_POINT_PARAMETERXV = 113;
0189: public static final int CMD_POINT_SIZE = 114;
0190: public static final int CMD_POINT_SIZEX = 115;
0191: public static final int CMD_POINT_SIZE_POINTER = 116;
0192: public static final int CMD_POINT_SIZE_POINTER_VBO = 117;
0193: public static final int CMD_POLYGON_OFFSET = 118;
0194: public static final int CMD_POLYGON_OFFSETX = 119;
0195: public static final int CMD_POP_MATRIX = 120;
0196: public static final int CMD_PUSH_MATRIX = 121;
0197: public static final int CMD_ROTATEF = 122;
0198: public static final int CMD_ROTATEX = 123;
0199: public static final int CMD_SAMPLE_COVERAGE = 124;
0200: public static final int CMD_SAMPLE_COVERAGEX = 125;
0201: public static final int CMD_SCALEF = 126;
0202: public static final int CMD_SCALEX = 127;
0203: public static final int CMD_SCISSOR = 128;
0204: public static final int CMD_SHADE_MODEL = 129;
0205: public static final int CMD_STENCIL_FUNC = 130;
0206: public static final int CMD_STENCIL_MASK = 131;
0207: public static final int CMD_STENCIL_OP = 132;
0208: public static final int CMD_TEX_COORD_POINTER = 133;
0209: public static final int CMD_TEX_COORD_POINTER_VBO = 134;
0210: public static final int CMD_TEX_ENVF = 135;
0211: public static final int CMD_TEX_ENVFB = 136;
0212: public static final int CMD_TEX_ENVFV = 137;
0213: public static final int CMD_TEX_ENVI = 138;
0214: public static final int CMD_TEX_ENVIB = 139;
0215: public static final int CMD_TEX_ENVIV = 140;
0216: public static final int CMD_TEX_ENVX = 141;
0217: public static final int CMD_TEX_ENVXB = 142;
0218: public static final int CMD_TEX_ENVXV = 143;
0219: public static final int CMD_TEX_IMAGE_2D = 144;
0220: public static final int CMD_TEX_PARAMETERF = 145;
0221: public static final int CMD_TEX_PARAMETERFB = 146;
0222: public static final int CMD_TEX_PARAMETERFV = 147;
0223: public static final int CMD_TEX_PARAMETERI = 148;
0224: public static final int CMD_TEX_PARAMETERIB = 149;
0225: public static final int CMD_TEX_PARAMETERIV = 150;
0226: public static final int CMD_TEX_PARAMETERX = 151;
0227: public static final int CMD_TEX_PARAMETERXB = 152;
0228: public static final int CMD_TEX_PARAMETERXV = 153;
0229: public static final int CMD_TEX_SUB_IMAGE_2D = 154;
0230: public static final int CMD_TRANSLATEF = 155;
0231: public static final int CMD_TRANSLATEX = 156;
0232: public static final int CMD_VERTEX_POINTER = 157;
0233: public static final int CMD_VERTEX_POINTER_VBO = 158;
0234: public static final int CMD_VIEWPORT = 159;
0235: public static final int CMD_WEIGHT_POINTER = 160;
0236: public static final int CMD_WEIGHT_POINTER_VBO = 161;
0237: public static final int CMD_FINISH = 162;
0238: public static final int CMD_FLUSH = 163;
0239: public static final int CMD_TEX_GENF = 164;
0240: public static final int CMD_TEX_GENI = 165;
0241: public static final int CMD_TEX_GENX = 166;
0242: public static final int CMD_TEX_GENFB = 167;
0243: public static final int CMD_TEX_GENIB = 168;
0244: public static final int CMD_TEX_GENXB = 169;
0245: public static final int CMD_TEX_GENFV = 170;
0246: public static final int CMD_TEX_GENIV = 171;
0247: public static final int CMD_TEX_GENXV = 172;
0248: public static final int CMD_BLEND_EQUATION = 173;
0249: public static final int CMD_BLEND_FUNC_SEPARATE = 174;
0250: public static final int CMD_BLEND_EQUATION_SEPARATE = 175;
0251: public static final int CMD_BIND_RENDERBUFFER = 176;
0252: public static final int CMD_DELETE_RENDERBUFFERS = 177;
0253: public static final int CMD_DELETE_RENDERBUFFERSB = 178;
0254: public static final int CMD_GEN_RENDERBUFFERSB = 179;
0255: public static final int CMD_RENDERBUFFER_STORAGE = 180;
0256: public static final int CMD_BIND_FRAMEBUFFER = 181;
0257: public static final int CMD_DELETE_FRAMEBUFFERS = 182;
0258: public static final int CMD_DELETE_FRAMEBUFFERSB = 183;
0259: public static final int CMD_GEN_FRAMEBUFFERSB = 184;
0260: public static final int CMD_FRAMEBUFFER_TEXTURE2D = 185;
0261: public static final int CMD_FRAMEBUFFER_RENDERBUFFER = 186;
0262: public static final int CMD_GENERATE_MIPMAP = 187;
0263: public static final int CMD_GEN_BUFFERSB = 188;
0264: public static final int CMD_GEN_TEXTURESB = 189;
0265:
0266: static final String[] commandStrings = { null,
0267: "CMD_ACTIVE_TEXTURE", "ALPHA_FUNC", "ALPHA_FUNCX",
0268: "BIND_BUFFER", "BIND_TEXTURE", "BLEND_FUNC", "BUFFER_DATA",
0269: "BUFFER_SUB_DATA", "CLEAR", "CLEAR_COLOR", "CLEAR_COLORX",
0270: "CLEAR_DEPTHF", "CLEAR_DEPTHX", "CLEAR_STENCIL",
0271: "CLIENT_ACTIVE_TEXTURE", "CLIP_PLANEF", "CLIP_PLANEFB",
0272: "CLIP_PLANEX", "CLIP_PLANEXB", "COLOR4F", "COLOR4X",
0273: "COLOR4UB", "COLOR_MASK", "COLOR_POINTER",
0274: "COLOR_POINTER_VBO", "COMPRESSED_TEX_IMAGE_2D",
0275: "COMPRESSED_TEX_SUB_IMAGE_2D", "COPY_TEX_IMAGE_2D",
0276: "COPY_TEX_SUB_IMAGE_2D", "CULL_FACE",
0277: "CURRENT_PALETTE_MATRIX", "DELETE_BUFFERS",
0278: "DELETE_BUFFERSB", "DELETE_TEXTURES", "DELETE_TEXTURESB",
0279: "DEPTH_FUNC", "DEPTH_MASK", "DEPTH_RANGEF", "DEPTH_RANGEX",
0280: "DISABLE", "DISABLE_CLIENT_STATE", "DRAW_ARRAYS",
0281: "DRAW_ELEMENTSB", "DRAW_ELEMENTS_VBO", "DRAW_TEXF",
0282: "DRAW_TEXFB", "DRAW_TEXI", "DRAW_TEXIB", "DRAW_TEXS",
0283: "DRAW_TEXSB", "DRAW_TEXX", "DRAW_TEXXB", "ENABLE",
0284: "ENABLE_CLIENT_STATE", "FOGF", "FOGFB", "FOGFV", "FOGX",
0285: "FOGXB", "FOGXV", "FRONT_FACE", "FRUSTUMF", "FRUSTUMX",
0286: "HINT", "LIGHTF", "LIGHTFB", "LIGHTFV", "LIGHTX",
0287: "LIGHTXB", "LIGHTXV", "LIGHT_MODELF", "LIGHT_MODELFB",
0288: "LIGHT_MODELFV", "LIGHT_MODELX", "LIGHT_MODELXB",
0289: "LIGHT_MODELXV", "LINE_WIDTH", "LINE_WIDTHX",
0290: "LOAD_IDENTITY", "LOAD_MATRIXF", "LOAD_MATRIXFB",
0291: "LOAD_MATRIXX", "LOAD_MATRIXXB",
0292: "LOAD_PALETTE_FROM_MODEL_VIEW_MATRIX", "LOGIC_OP",
0293: "MATERIALF", "MATERIALFB", "MATERIALFV", "MATERIALX",
0294: "MATERIALXB", "MATERIALXV", "MATRIX_INDEX_POINTER",
0295: "MATRIX_INDEX_POINTER_VBO", "MATRIX_MODE",
0296: "MULTI_TEXT_COORD4F", "MULTI_TEXT_COORD4X", "MULT_MATRIXF",
0297: "MULT_MATRIXFB", "MULT_MATRIXX", "MULT_MATRIXXB",
0298: "NORMAL3F", "NORMAL3X", "NORMAL_POINTER",
0299: "NORMAL_POINTER_VBO", "ORTHOF", "ORTHOX", "PIXEL_STOREI",
0300: "POINT_PARAMETERF", "POINT_PARAMETERFB",
0301: "POINT_PARAMETERFV", "POINT_PARAMETERX",
0302: "POINT_PARAMETERXB", "POINT_PARAMETERXV", "POINT_SIZE",
0303: "POINT_SIZEX", "POINT_SIZE_POINTER",
0304: "POINT_SIZE_POINTER_VBO", "POLYGON_OFFSET",
0305: "POLYGON_OFFSETX", "POP_MATRIX", "PUSH_MATRIX", "ROTATEF",
0306: "ROTATEX", "SAMPLE_COVERAGE", "SAMPLE_COVERAGEX", "SCALEF",
0307: "SCALEX", "SCISSOR", "SHADE_MODEL", "STENCIL_FUNC",
0308: "STENCIL_MASK", "STENCIL_OP", "TEX_COORD_POINTER",
0309: "TEX_COORD_POINTER_VBO", "TEX_ENVF", "TEX_ENVFB",
0310: "TEX_ENVFV", "TEX_ENVI", "TEX_ENVIB", "TEX_ENVIV",
0311: "TEX_ENVX", "TEX_ENVXB", "TEX_ENVXV", "TEX_IMAGE_2D",
0312: "TEX_PARAMETERF", "TEX_PARAMETERFB", "TEX_PARAMETERFV",
0313: "TEX_PARAMETERI", "TEX_PARAMETERIB", "TEX_PARAMETERIV",
0314: "TEX_PARAMETERX", "TEX_PARAMETERXB", "TEX_PARAMETERXV",
0315: "TEX_SUB_IMAGE_2D", "TRANSLATEF", "TRANSLATEX",
0316: "VERTEX_POINTER", "VERTEX_POINTER_VBO", "VIEWPORT",
0317: "WEIGHT_POINTER", "WEIGHT_POINTER_VBO", "FINISH", "FLUSH",
0318: "TEX_GENF", "TEX_GENI", "TEX_GENX", "TEX_GENFB",
0319: "TEX_GENIB", "TEX_GENXB", "TEX_GENFV", "TEX_GENIV",
0320: "TEX_GENXV", "BLEND_EQUATION", "BLEND_FUNC_SEPARATE",
0321: "BLEND_EQUATION_SEPARATE", "BIND_RENDERBUFFER",
0322: "DELETE_RENDERBUFFERS", "DELETE_RENDERBUFFERSB",
0323: "GEN_RENDERBUFFERSB", "RENDERBUFFER_STORAGE",
0324: "BIND_FRAMEBUFFER", "DELETE_FRAMEBUFFERS",
0325: "DELETE_FRAMEBUFFERSB", "GEN_FRAMEBUFFERSB",
0326: "FRAMEBUFFER_TEXTURE2D", "FRAMEBUFFER_RENDERBUFFER",
0327: "GENERATE_MIPMAP", "GEN_BUFFERSB", "GEN_TEXTURESB" };
0328:
0329: native void _glGenerateError(int error);
0330:
0331: native void _glGenBuffers(int n, int[] buffers, int offset);
0332:
0333: native void _glGenTextures(int n, int[] textures, int offset);
0334:
0335: native int _glGetError();
0336:
0337: native void _glGetIntegerv(int pname, int[] params, int offset,
0338: int length);
0339:
0340: native String _glGetString(int name);
0341:
0342: native void _glGetBooleanv(int pname, int[] params, int offset,
0343: int length);
0344:
0345: native void _glGetFixedv(int pname, int[] params, int offset,
0346: int length);
0347:
0348: native void _glGetFloatv(int pname, float[] params, int offset,
0349: int length);
0350:
0351: native void _glGetLightfv(int light, int pname, float[] params,
0352: int offset, int length);
0353:
0354: native void _glGetMaterialfv(int face, int pname, float[] params,
0355: int offset, int length);
0356:
0357: native void _glGetMaterialxv(int face, int pname, int[] params,
0358: int offset, int length);
0359:
0360: native void _glGetLightxv(int light, int pname, int[] params,
0361: int offset, int length);
0362:
0363: native void _glGetTexEnvfv(int env, int pname, float[] params,
0364: int offset, int length);
0365:
0366: native void _glGetTexEnviv(int env, int pname, int[] params,
0367: int offset, int length);
0368:
0369: native void _glGetTexEnvxv(int env, int pname, int[] params,
0370: int offset, int length);
0371:
0372: native void _glGetTexParameterfv(int target, int pname,
0373: float[] params, int offset, int length);
0374:
0375: native void _glGetTexParameteriv(int target, int pname,
0376: int[] params, int offset, int length);
0377:
0378: native void _glGetTexParameterxv(int target, int pname,
0379: int[] params, int offset, int length);
0380:
0381: native void _glGetBufferParameteriv(int target, int pname,
0382: int[] params, int offset, int length);
0383:
0384: native void _glGetClipPlanef(int pname, float[] eqn, int offset);
0385:
0386: native void _glGetClipPlanex(int pname, int[] eqn, int offset);
0387:
0388: native int _glIsBuffer(int buffer);
0389:
0390: native int _glIsEnabled(int cap);
0391:
0392: native int _glIsTexture(int texture);
0393:
0394: native void _glReadPixelsPtr(int x, int y, int width, int height,
0395: int format, int type, int pointer);
0396:
0397: native void _glReadPixelsByte(int x, int y, int width, int height,
0398: int format, int type, byte[] array, int offset);
0399:
0400: native void _glReadPixelsInt(int x, int y, int width, int height,
0401: int format, int type, int[] array, int offset);
0402:
0403: // OES_query_matrix
0404:
0405: native int _glQueryMatrixxOES(int[] mantissa, int mantissaOffset,
0406: int[] exponent, int exponentOffset);
0407:
0408: // OES_texture_cube_map
0409:
0410: native int _glGetTexGenfv(int coord, int pname, float[] params,
0411: int offset, int length);
0412:
0413: native int _glGetTexGeniv(int coord, int pname, int[] params,
0414: int offset, int length);
0415:
0416: native int _glGetTexGenxv(int coord, int pname, int[] params,
0417: int offset, int length);
0418:
0419: // OES_framebuffer_object
0420:
0421: native int _glIsRenderbufferOES(int renderbuffer);
0422:
0423: native void _glGenRenderbuffersOES(int n, int[] renderbuffers,
0424: int offset);
0425:
0426: native void _glGetRenderbufferParameterivOES(int target, int pname,
0427: int[] params, int offset, int length);
0428:
0429: native int _glIsFramebufferOES(int framebuffer);
0430:
0431: native void _glGenFramebuffersOES(int n, int[] framebuffers,
0432: int offset);
0433:
0434: native int _glCheckFramebufferStatusOES(int target);
0435:
0436: native void _glGetFramebufferAttachmentParameterivOES(int target,
0437: int attachment, int pname, int[] params, int offset,
0438: int length);
0439:
0440: // Execute a queue of GL commands
0441: native void _execute(int[] queue, int count);
0442:
0443: int[] queue = new int[GLConfiguration.COMMAND_QUEUE_SIZE];
0444: int index = 0;
0445:
0446: int commandsLeft;
0447:
0448: void throwIAE(String message) {
0449: throw new IllegalArgumentException(message);
0450: }
0451:
0452: public void qflush() {
0453: if (debugQueue) {
0454: System.out.println("Flushing the queue, index = " + index);
0455: }
0456: grabContext();
0457: _execute(queue, index);
0458: index = 0;
0459:
0460: // Ensure GL does not starve other threads
0461: Thread.yield();
0462: }
0463:
0464: void q(int cmd, int count) {
0465: if (index + count + 1 >= GLConfiguration.COMMAND_QUEUE_SIZE) {
0466: qflush();
0467: }
0468: if (debugQueue) {
0469: System.out.println("Queueing command "
0470: + commandStrings[cmd] + " with " + count
0471: + " args from thread " + Thread.currentThread());
0472: }
0473: queue[index++] = cmd;
0474: commandsLeft = count;
0475: }
0476:
0477: void q(int i) {
0478: queue[index++] = i;
0479:
0480: if (debugQueue) {
0481: System.out.println("Queueing integer " + i
0482: + " from thread " + Thread.currentThread());
0483: }
0484:
0485: if (GLConfiguration.flushQueueAfterEachCommand
0486: && (--commandsLeft == 0)) {
0487: if (debugQueue) {
0488: System.out.println("Last arg for command, flushing");
0489: }
0490: qflush();
0491: }
0492: }
0493:
0494: int floatToIntBits(float f) {
0495: int i = Float.floatToIntBits(f);
0496: if (GLConfiguration.SWAP_FLOAT_BYTES) {
0497: // Start: AABBCCDD
0498: // End: DDCCBBAA
0499: i = (((i << 24) & 0xff000000) | ((i << 8) & 0x00ff0000)
0500: | ((i >> 8) & 0x0000ff00) | ((i >> 24) & 0x000000ff));
0501: }
0502: return i;
0503: }
0504:
0505: void q(float f) {
0506: int i = floatToIntBits(f);
0507: queue[index++] = i;
0508:
0509: if (debugQueue) {
0510: System.out.println("Queueing float " + f + " from thread "
0511: + Thread.currentThread());
0512: }
0513:
0514: if (GLConfiguration.flushQueueAfterEachCommand
0515: && (--commandsLeft == 0)) {
0516: if (debugQueue) {
0517: System.out.println("Last arg for command, flushing");
0518: }
0519: qflush();
0520: }
0521: }
0522:
0523: // offset will be shifted according to the buffer datatype
0524: // and added to the native base address
0525: static native int _getNativeAddress(Buffer buffer, int offset);
0526:
0527: int pointer(Buffer buffer) {
0528: int offset = buffer.position();
0529: int nativeAddress = _getNativeAddress(buffer, offset);
0530:
0531: return nativeAddress;
0532: }
0533:
0534: int offset(ByteBuffer buffer) {
0535: return buffer.arrayOffset() + buffer.position();
0536: }
0537:
0538: int offset(ShortBuffer buffer) {
0539: return buffer.arrayOffset() + buffer.position();
0540: }
0541:
0542: int offset(IntBuffer buffer) {
0543: return buffer.arrayOffset() + buffer.position();
0544: }
0545:
0546: int offset(FloatBuffer buffer) {
0547: return buffer.arrayOffset() + buffer.position();
0548: }
0549:
0550: void q(Buffer buf) {
0551: q(pointer(buf));
0552:
0553: if (debugQueue) {
0554: System.out.println("Queueing buffer pointer "
0555: + pointer(buf) + " from thread "
0556: + Thread.currentThread());
0557: }
0558:
0559: if (GLConfiguration.flushQueueAfterEachCommand
0560: && (--commandsLeft == 0)) {
0561: if (debugQueue) {
0562: System.out.println("Last arg for command, flushing");
0563: }
0564: qflush();
0565: }
0566: }
0567:
0568: boolean isDirect(Buffer buf) {
0569: if (buf instanceof ByteBuffer) {
0570: return ((ByteBuffer) buf).isDirect();
0571: } else if (buf instanceof ShortBuffer) {
0572: return ((ShortBuffer) buf).isDirect();
0573: } else if (buf instanceof IntBuffer) {
0574: return ((IntBuffer) buf).isDirect();
0575: } else if (buf instanceof FloatBuffer) {
0576: return ((FloatBuffer) buf).isDirect();
0577: } else {
0578: throw new IllegalArgumentException(Errors.GL_UNKNOWN_BUFFER);
0579: }
0580: }
0581:
0582: Buffer createDirectCopy(Buffer data) {
0583: int length = data.remaining();
0584:
0585: ByteBuffer direct;
0586: if (data instanceof ByteBuffer) {
0587: direct = ByteBuffer.allocateDirect(length);
0588: direct.put((ByteBuffer) data);
0589: return direct;
0590: } else if (data instanceof ShortBuffer) {
0591: direct = ByteBuffer.allocateDirect(2 * length);
0592: ShortBuffer directShort = direct.asShortBuffer();
0593: directShort.put((ShortBuffer) data);
0594: return directShort;
0595: } else if (data instanceof IntBuffer) {
0596: direct = ByteBuffer.allocateDirect(4 * length);
0597: IntBuffer directInt = direct.asIntBuffer();
0598: directInt.put((IntBuffer) data);
0599: return directInt;
0600: } else if (data instanceof FloatBuffer) {
0601: direct = ByteBuffer.allocateDirect(4 * length);
0602: FloatBuffer directFloat = direct.asFloatBuffer();
0603: directFloat.put((FloatBuffer) data);
0604: return directFloat;
0605: } else {
0606: throw new IllegalArgumentException(Errors.GL_UNKNOWN_BUFFER);
0607: }
0608: }
0609:
0610: /**
0611: * Utility for common error checking.
0612: *
0613: * @exception <code>IllegalArgumentException</code> if
0614: * <code>param</code> is <code>null</code> or shorter than
0615: * <code>length</code>.
0616: */
0617: void checkLength(boolean[] params, int length, int offset) {
0618: if (params == null) {
0619: throwIAE(Errors.GL_PARAMS_NULL);
0620: }
0621: if (offset < 0) {
0622: throwIAE(Errors.GL_OFFSET_NEGATIVE);
0623: }
0624: if (params.length - offset < length) {
0625: throwIAE(Errors.GL_BAD_LENGTH);
0626: }
0627: }
0628:
0629: /**
0630: * Utility for common error checking.
0631: *
0632: * @exception <code>IllegalArgumentException</code> if
0633: * <code>param</code> is <code>null</code> or shorter than
0634: * <code>length</code>.
0635: */
0636: void checkLength(short[] params, int length, int offset) {
0637: if (params == null) {
0638: throwIAE(Errors.GL_PARAMS_NULL);
0639: }
0640: if (offset < 0) {
0641: throwIAE(Errors.GL_OFFSET_NEGATIVE);
0642: }
0643: if (params.length - offset < length) {
0644: throwIAE(Errors.GL_BAD_LENGTH);
0645: }
0646: }
0647:
0648: /**
0649: * Utility for common error checking.
0650: *
0651: * @exception <code>IllegalArgumentException</code> if
0652: * <code>param</code> is <code>null</code> or shorter than
0653: * <code>length</code>.
0654: */
0655: void checkLength(int[] params, int length, int offset) {
0656: if (params == null) {
0657: throwIAE(Errors.GL_PARAMS_NULL);
0658: }
0659: if (offset < 0) {
0660: throwIAE(Errors.GL_OFFSET_NEGATIVE);
0661: }
0662: if (params.length - offset < length) {
0663: throwIAE(Errors.GL_BAD_LENGTH);
0664: }
0665: }
0666:
0667: /**
0668: * Utility for common error checking.
0669: *
0670: * @exception <code>IllegalArgumentException</code> if
0671: * <code>param</code> is <code>null</code> or shorter than
0672: * <code>length</code>.
0673: */
0674: void checkLength(float[] params, int length, int offset) {
0675: if (params == null) {
0676: throwIAE(Errors.GL_PARAMS_NULL);
0677: }
0678: if (offset < 0) {
0679: throwIAE(Errors.GL_OFFSET_NEGATIVE);
0680: }
0681: if (params.length - offset < length) {
0682: throwIAE(Errors.GL_BAD_LENGTH);
0683: }
0684: }
0685:
0686: /**
0687: * Utility for common error checking.
0688: *
0689: * @exception <code>IllegalArgumentException</code> if
0690: * <code>param</code> is <code>null</code> or shorter than
0691: * <code>length</code>.
0692: */
0693: void checkLength(Buffer params, int length) {
0694: if (params == null) {
0695: throwIAE(Errors.GL_PARAMS_NULL);
0696: }
0697: if (params.remaining() < length) {
0698: throwIAE(Errors.GL_BAD_LENGTH);
0699: }
0700: }
0701:
0702: void checkThread() {
0703:
0704: Thread boundThread = ((ContextAccess) context).getBoundThread();
0705: if (Thread.currentThread() != boundThread) {
0706: throw new IllegalStateException(
0707: "GL call from improper thread");
0708: }
0709: }
0710:
0711: // If GLConfiguration.singleThreaded is true, the context that is
0712: // current on the (single) native thread, or EGL_NO_CONTEXT. If
0713: // singleThreaded is false, this variable has no meaning.
0714: public static EGLContext currentContext = EGL10.EGL_NO_CONTEXT;
0715:
0716: /**
0717: * IMPL_NOTE: <code>contextsByThread</code> may lead to the Java memory
0718: * leaks (when a thread dies, an associated context will not be ever
0719: * collected). As the possible workaround the following solution can be
0720: * used: a private <code>Hashtable</code> member can be added for class
0721: * <code>Thread</code> to keep a reference to the context. In this case
0722: * the life span of a context will not be longer then that of a thread.
0723: */
0724: // Map Thread -> EGLContext
0725: public static Hashtable contextsByThread = new Hashtable();
0726:
0727: // Current cull face mode for CR 6401385 workaround
0728: public int cullFaceMode = GL_BACK;
0729:
0730: /**
0731: * Set the context associated with the current Java thread as the
0732: * native context. This is only necessary if we are on a
0733: * single-threaded VM and the context is not already current.
0734: */
0735: public static void grabContext() {
0736: if (!GLConfiguration.singleThreaded) {
0737: return;
0738: }
0739:
0740: // Locate the desired context for this Java thread
0741: Thread currentThread = Thread.currentThread();
0742: EGLContext newContext = (EGLContext) contextsByThread
0743: .get(currentThread);
0744: if (newContext == GL10Impl.currentContext) {
0745: return;
0746: }
0747:
0748: if (newContext != null) {
0749: EGLDisplay display = ((ContextAccess) newContext)
0750: .getDisplay();
0751:
0752: EGLSurface draw = ((ContextAccess) newContext)
0753: .getDrawSurface();
0754:
0755: EGLSurface read = ((ContextAccess) newContext)
0756: .getReadSurface();
0757:
0758: egl.eglMakeCurrent(display, draw, read, newContext);
0759:
0760: GL10Impl.currentContext = newContext;
0761: }
0762: }
0763:
0764: // Begin GL methods
0765:
0766: public synchronized void glActiveTexture(int texture) {
0767: checkThread();
0768: q(CMD_ACTIVE_TEXTURE, 1);
0769: q(texture);
0770: }
0771:
0772: public synchronized void glAlphaFunc(int func, float ref) {
0773: checkThread();
0774: q(CMD_ALPHA_FUNC, 2);
0775: q(func);
0776: q(ref);
0777: }
0778:
0779: public synchronized void glAlphaFuncx(int func, int ref) {
0780: checkThread();
0781: q(CMD_ALPHA_FUNCX, 2);
0782: q(func);
0783: q(ref);
0784: }
0785:
0786: public synchronized void glBindTexture(int target, int texture) {
0787: checkThread();
0788: q(CMD_BIND_TEXTURE, 2);
0789: q(target);
0790: q(texture);
0791: }
0792:
0793: public synchronized void glBlendFunc(int sfactor, int dfactor) {
0794: checkThread();
0795: q(CMD_BLEND_FUNC, 2);
0796: q(sfactor);
0797: q(dfactor);
0798: }
0799:
0800: public synchronized void glClear(int mask) {
0801: checkThread();
0802: q(CMD_CLEAR, 1);
0803: q(mask);
0804: }
0805:
0806: public synchronized void glClearColor(float red, float green,
0807: float blue, float alpha) {
0808: checkThread();
0809: q(CMD_CLEAR_COLOR, 4);
0810: q(red);
0811: q(green);
0812: q(blue);
0813: q(alpha);
0814: }
0815:
0816: public synchronized void glClearColorx(int red, int green,
0817: int blue, int alpha) {
0818: checkThread();
0819: q(CMD_CLEAR_COLORX, 4);
0820: q(red);
0821: q(green);
0822: q(blue);
0823: q(alpha);
0824: }
0825:
0826: public synchronized void glClearDepthf(float depth) {
0827: checkThread();
0828: q(CMD_CLEAR_DEPTHF, 1);
0829: q(depth);
0830: }
0831:
0832: public synchronized void glClearDepthx(int depth) {
0833: checkThread();
0834: q(CMD_CLEAR_DEPTHX, 1);
0835: q(depth);
0836: }
0837:
0838: public synchronized void glClearStencil(int s) {
0839: checkThread();
0840: q(CMD_CLEAR_STENCIL, 1);
0841: q(s);
0842: }
0843:
0844: public synchronized void glClientActiveTexture(int texture) {
0845: checkThread();
0846: q(CMD_CLIENT_ACTIVE_TEXTURE, 1);
0847: q(texture);
0848: }
0849:
0850: void IglClipPlanef(int plane, float[] equation, int offset) {
0851: q(CMD_CLIP_PLANEF, 5);
0852: q(plane);
0853: q(equation[offset]);
0854: q(equation[offset + 1]);
0855: q(equation[offset + 2]);
0856: q(equation[offset + 3]);
0857: }
0858:
0859: void IglClipPlanex(int plane, int[] equation, int offset) {
0860: q(CMD_CLIP_PLANEX, 5);
0861: q(plane);
0862: q(equation[offset]);
0863: q(equation[offset + 1]);
0864: q(equation[offset + 2]);
0865: q(equation[offset + 3]);
0866: }
0867:
0868: public synchronized void glColor4f(float red, float green,
0869: float blue, float alpha) {
0870: checkThread();
0871: q(CMD_COLOR4F, 4);
0872: q(red);
0873: q(green);
0874: q(blue);
0875: q(alpha);
0876: }
0877:
0878: public synchronized void glColor4x(int red, int green, int blue,
0879: int alpha) {
0880: checkThread();
0881: q(CMD_COLOR4X, 4);
0882: q(red);
0883: q(green);
0884: q(blue);
0885: q(alpha);
0886: }
0887:
0888: public synchronized void glColor4ub(byte red, byte green,
0889: byte blue, byte alpha) {
0890: checkThread();
0891: q(CMD_COLOR4UB, 4);
0892: q((int) red);
0893: q((int) green);
0894: q((int) blue);
0895: q((int) alpha);
0896: }
0897:
0898: public synchronized void glColorMask(boolean red, boolean green,
0899: boolean blue, boolean alpha) {
0900: checkThread();
0901: q(CMD_COLOR_MASK, 4);
0902: q(red ? 1 : 0);
0903: q(green ? 1 : 0);
0904: q(blue ? 1 : 0);
0905: q(alpha ? 1 : 0);
0906: }
0907:
0908: public synchronized void glColorPointer(int size, int type,
0909: int stride, Buffer pointer) {
0910: checkThread();
0911: if (VBOArrayBufferBound != 0) {
0912: throw new IllegalStateException("glColorPointer:"
0913: + Errors.VBO_ARRAY_BUFFER_BOUND);
0914: }
0915: if (pointer == null) {
0916: throwIAE(Errors.GL_POINTER_NULL);
0917: }
0918: if (!isDirect(pointer)) {
0919: throwIAE(Errors.GL_NOT_DIRECT);
0920: }
0921:
0922: // Only record details if this is a legal operation
0923: if ((size == 4)
0924: && (type == GL_UNSIGNED_BYTE || type == GL_FIXED || type == GL_FLOAT)
0925: && (stride >= 0)) {
0926: BufferManager.releaseBuffer(pointerBuffer[COLOR_POINTER]);
0927: BufferManager.useBuffer(pointer);
0928:
0929: pointerBuffer[COLOR_POINTER] = pointer;
0930: pointerSize[COLOR_POINTER] = size;
0931: pointerType[COLOR_POINTER] = type;
0932: pointerStride[COLOR_POINTER] = stride;
0933: int nbytes = bufferTypeSize(pointer);
0934: pointerRemaining[COLOR_POINTER] = pointer.remaining()
0935: * nbytes;
0936: pointerOffset[COLOR_POINTER] = 0;
0937: }
0938:
0939: q(CMD_COLOR_POINTER, 4);
0940: q(size);
0941: q(type);
0942: q(stride);
0943: q(pointer);
0944:
0945: qflush();
0946: }
0947:
0948: public synchronized void glCompressedTexImage2D(int target,
0949: int level, int internalformat, int width, int height,
0950: int border, int imageSize, Buffer data) {
0951: checkThread();
0952: checkLength(data, imageSize);
0953:
0954: boolean isReadOnly = false;
0955: if (!isDirect(data)) {
0956: data = createDirectCopy(data);
0957: isReadOnly = true;
0958: }
0959:
0960: // Need revisit: BufferManager stuff
0961:
0962: q(CMD_COMPRESSED_TEX_IMAGE_2D, 8);
0963: q(target);
0964: q(level);
0965: q(internalformat);
0966: q(width);
0967: q(height);
0968: q(border);
0969: q(imageSize);
0970: q(data);
0971:
0972: if (!isReadOnly) {
0973: qflush();
0974: }
0975: }
0976:
0977: public synchronized void glCompressedTexSubImage2D(int target,
0978: int level, int xoffset, int yoffset, int width, int height,
0979: int format, int imageSize, Buffer data) {
0980: checkThread();
0981: checkLength(data, imageSize);
0982:
0983: boolean isReadOnly = false;
0984: if (!isDirect(data)) {
0985: data = createDirectCopy(data);
0986: isReadOnly = true;
0987: }
0988:
0989: // Need revisit: BufferManager stuff
0990:
0991: q(CMD_COMPRESSED_TEX_SUB_IMAGE_2D, 9);
0992: q(target);
0993: q(level);
0994: q(xoffset);
0995: q(yoffset);
0996: q(width);
0997: q(height);
0998: q(format);
0999: q(imageSize);
1000: q(data);
1001:
1002: if (!isReadOnly) {
1003: qflush();
1004: }
1005: }
1006:
1007: public synchronized void glCopyTexImage2D(int target, int level,
1008: int internalformat, int x, int y, int width, int height,
1009: int border) {
1010: checkThread();
1011: q(CMD_COPY_TEX_IMAGE_2D, 8);
1012: q(target);
1013: q(level);
1014: q(internalformat);
1015: q(x);
1016: q(y);
1017: q(width);
1018: q(height);
1019: q(border);
1020: }
1021:
1022: public synchronized void glCopyTexSubImage2D(int target, int level,
1023: int xoffset, int yoffset, int x, int y, int width,
1024: int height) {
1025: checkThread();
1026: q(CMD_COPY_TEX_SUB_IMAGE_2D, 8);
1027: q(target);
1028: q(level);
1029: q(xoffset);
1030: q(yoffset);
1031: q(x);
1032: q(y);
1033: q(width);
1034: q(height);
1035: }
1036:
1037: public synchronized void glCullFace(int mode) {
1038: checkThread();
1039: q(CMD_CULL_FACE, 1);
1040: q(mode);
1041:
1042: // Workaround for Gerbera bug, CR 6401385
1043: cullFaceMode = mode;
1044: }
1045:
1046: public synchronized void glDeleteTextures(int n, int[] textures,
1047: int offset) {
1048: checkThread();
1049: checkLength(textures, n, offset);
1050:
1051: IglDeleteTextures(n, textures, offset);
1052: }
1053:
1054: public synchronized void glDeleteTextures(int n, IntBuffer textures) {
1055: checkThread();
1056: // Need revisit: defend against race condition
1057: checkLength(textures, n);
1058:
1059: if (!textures.isDirect()) {
1060: IglDeleteTextures(n, textures.array(), offset(textures));
1061: return;
1062: }
1063:
1064: // Queue pointer
1065: q(CMD_DELETE_TEXTURESB, 2);
1066: q(n);
1067: q(textures);
1068:
1069: qflush();
1070: }
1071:
1072: void IglDeleteTextures(int n, int[] textures, int offset) {
1073: q(CMD_DELETE_TEXTURES, n + 1);
1074: q(n);
1075: for (int i = 0; i < n; i++) {
1076: q(textures[i + offset]);
1077: }
1078: }
1079:
1080: public synchronized void glDepthFunc(int func) {
1081: checkThread();
1082: q(CMD_DEPTH_FUNC, 1);
1083: q(func);
1084: }
1085:
1086: public synchronized void glDepthMask(boolean flag) {
1087: checkThread();
1088: q(CMD_DEPTH_MASK, 1);
1089: q(flag ? 1 : 0);
1090: }
1091:
1092: public synchronized void glDepthRangef(float zNear, float zFar) {
1093: checkThread();
1094: q(CMD_DEPTH_RANGEF, 2);
1095: q(zNear);
1096: q(zFar);
1097: }
1098:
1099: public synchronized void glDepthRangex(int zNear, int zFar) {
1100: checkThread();
1101: q(CMD_DEPTH_RANGEX, 2);
1102: q(zNear);
1103: q(zFar);
1104: }
1105:
1106: public synchronized void glDisable(int cap) {
1107: checkThread();
1108: q(CMD_DISABLE, 1);
1109: q(cap);
1110: }
1111:
1112: public synchronized void glDisableClientState(int array) {
1113: checkThread();
1114:
1115: switch (array) {
1116: case GL_VERTEX_ARRAY:
1117: pointerEnabled[VERTEX_POINTER] = false;
1118: break;
1119: case GL_COLOR_ARRAY:
1120: pointerEnabled[COLOR_POINTER] = false;
1121: break;
1122: case GL_NORMAL_ARRAY:
1123: pointerEnabled[NORMAL_POINTER] = false;
1124: break;
1125: case GL_TEXTURE_COORD_ARRAY:
1126: pointerEnabled[TEX_COORD_POINTER] = false;
1127: break;
1128: case GL11.GL_POINT_SIZE_ARRAY_OES:
1129: pointerEnabled[POINT_SIZE_POINTER] = false;
1130: break;
1131: case GL11Ext.GL_MATRIX_INDEX_ARRAY_OES:
1132: pointerEnabled[MATRIX_INDEX_POINTER] = false;
1133: break;
1134: case GL11Ext.GL_WEIGHT_ARRAY_OES:
1135: pointerEnabled[WEIGHT_POINTER] = false;
1136: break;
1137: }
1138:
1139: q(CMD_DISABLE_CLIENT_STATE, 1);
1140: q(array);
1141: }
1142:
1143: void checkBounds(int last) {
1144: for (int ptr = VERTEX_POINTER; ptr <= WEIGHT_POINTER; ptr++) {
1145: if (pointerEnabled[ptr]) {
1146: final int remaining = (pointerBuffer[ptr] != null) ? pointerRemaining[ptr]
1147: : getBufferSize(GL11.GL_ARRAY_BUFFER);
1148: final int size = pointerSize[ptr];
1149: final int type = pointerType[ptr];
1150: final int offset = pointerOffset[ptr];
1151: final int sizeOfType = GLConfiguration.sizeOfType(type);
1152: final int stride = pointerStride[ptr] == 0 ? sizeOfType
1153: : pointerStride[ptr];
1154: final int elementSize = size * sizeOfType;
1155:
1156: final int lastByte = offset + last * stride
1157: + elementSize;
1158:
1159: if (lastByte > remaining) {
1160: throw new ArrayIndexOutOfBoundsException(String
1161: .valueOf(lastByte));
1162: }
1163: }
1164: }
1165: }
1166:
1167: public synchronized void glDrawArrays(int mode, int first, int count) {
1168: checkThread();
1169:
1170: checkBounds(first + count - 1);
1171:
1172: q(CMD_DRAW_ARRAYS, 3);
1173: q(mode);
1174: q(first);
1175: q(count);
1176: }
1177:
1178: void checkIndices(int[] indices) {
1179: int count = indices.length;
1180:
1181: // System.out.println("checkIndices:");
1182: // System.out.println(" indices = ");
1183: // for (int i = 0; i < indices.length; i++) {
1184: // System.out.print(indices[i] + " ");
1185: // }
1186: // System.out.println();
1187:
1188: for (int ptr = VERTEX_POINTER; ptr <= WEIGHT_POINTER; ptr++) {
1189: // System.out.println("ptr = " + ptr);
1190: if (pointerEnabled[ptr]) {
1191: int size, type, stride, offset, remaining;
1192:
1193: if (pointerBuffer[ptr] != null) {
1194: remaining = pointerRemaining[ptr];
1195: } else {
1196: remaining = getBufferSize(GL11.GL_ARRAY_BUFFER);
1197: }
1198: // System.out.println("remaining = " + remaining);
1199: size = pointerSize[ptr];
1200: type = pointerType[ptr];
1201: stride = pointerStride[ptr];
1202: offset = pointerOffset[ptr];
1203:
1204: // System.out.println("size = " + size);
1205: // System.out.println("type = " + type);
1206: // System.out.println("stride = " + stride);
1207: // System.out.println("offset = " + offset);
1208:
1209: int elementSize = size
1210: * GLConfiguration.sizeOfType(type);
1211: // System.out.println("elementSize = " + elementSize);
1212:
1213: for (int i = 0; i < count; i++) {
1214: int idx = indices[i];
1215: int bidx = offset + idx * (elementSize + stride)
1216: + elementSize;
1217:
1218: // System.out.println("bidx[" + i + "] = " + bidx);
1219: if (bidx > remaining) {
1220: throw new ArrayIndexOutOfBoundsException(""
1221: + bidx);
1222: }
1223: }
1224: }
1225: }
1226: }
1227:
1228: void checkDrawElementsBounds(byte[] indices) {
1229: }
1230:
1231: public synchronized void glDrawElements(int mode, int count,
1232: int type, Buffer indices) {
1233: checkThread();
1234: if (VBOElementArrayBufferBound != 0) {
1235: throw new IllegalStateException("glDrawElements:"
1236: + Errors.VBO_ELEMENT_ARRAY_BUFFER_BOUND);
1237: }
1238: if (indices == null) {
1239: throwIAE(Errors.GL_INDICES_NULL);
1240: }
1241:
1242: boolean isReadOnly = false;
1243: if (!isDirect(indices)) {
1244: indices = createDirectCopy(indices);
1245: isReadOnly = true;
1246: }
1247:
1248: // No need to bounds check if there will be a type error
1249: if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_SHORT) {
1250: int nbytes = (type == GL_UNSIGNED_BYTE) ? 1 : 2;
1251:
1252: if (count > indices.remaining()) {
1253: throw new ArrayIndexOutOfBoundsException(
1254: Errors.VBO_OFFSET_OOB);
1255: }
1256:
1257: if (DEBUG_MEM) {
1258: System.out
1259: .print("glDrawElements: Allocating bufferData "
1260: + count * nbytes);
1261: }
1262: byte[] bufferData = new byte[count * nbytes];
1263: BufferManager.getBytes(indices, 0, bufferData, 0, count
1264: * nbytes);
1265:
1266: if (DEBUG_MEM) {
1267: System.out.println(": done");
1268: System.out
1269: .print("glDrawElements: Allocating indexArray "
1270: + count);
1271: }
1272: int[] indexArray = new int[count];
1273: boolean isBigEndian = GLConfiguration.IS_BIG_ENDIAN;
1274: if (DEBUG_MEM) {
1275: System.out.println(": done");
1276: }
1277:
1278: if (type == GL_UNSIGNED_BYTE) {
1279: for (int i = 0; i < count; i++) {
1280: indexArray[i] = bufferData[i] & 0xff;
1281: }
1282: } else if (type == GL_UNSIGNED_SHORT) {
1283: for (int i = 0; i < count; i++) {
1284: int b0 = bufferData[2 * i] & 0xff;
1285: int b1 = bufferData[2 * i + 1] & 0xff;
1286: if (isBigEndian) {
1287: indexArray[i] = (b0 << 8) | b1;
1288: } else {
1289: indexArray[i] = (b1 << 8) | b0;
1290: }
1291: }
1292: }
1293:
1294: checkIndices(indexArray);
1295: }
1296:
1297: q(CMD_DRAW_ELEMENTSB, 4);
1298: q(mode);
1299: q(count);
1300: q(type);
1301: q(indices);
1302:
1303: if (!isReadOnly) {
1304: qflush();
1305: }
1306: }
1307:
1308: public synchronized void glEnable(int cap) {
1309: checkThread();
1310: q(CMD_ENABLE, 1);
1311: q(cap);
1312: }
1313:
1314: public synchronized void glEnableClientState(int array) {
1315: checkThread();
1316:
1317: switch (array) {
1318: case GL_VERTEX_ARRAY:
1319: pointerEnabled[VERTEX_POINTER] = true;
1320: break;
1321: case GL_COLOR_ARRAY:
1322: pointerEnabled[COLOR_POINTER] = true;
1323: break;
1324: case GL_NORMAL_ARRAY:
1325: pointerEnabled[NORMAL_POINTER] = true;
1326: break;
1327: case GL_TEXTURE_COORD_ARRAY:
1328: pointerEnabled[TEX_COORD_POINTER] = true;
1329: break;
1330: case GL11.GL_POINT_SIZE_ARRAY_OES:
1331: pointerEnabled[POINT_SIZE_POINTER] = true;
1332: break;
1333: case GL11Ext.GL_MATRIX_INDEX_ARRAY_OES:
1334: pointerEnabled[MATRIX_INDEX_POINTER] = true;
1335: break;
1336: case GL11Ext.GL_WEIGHT_ARRAY_OES:
1337: pointerEnabled[WEIGHT_POINTER] = true;
1338: break;
1339: }
1340:
1341: q(CMD_ENABLE_CLIENT_STATE, 1);
1342: q(array);
1343: }
1344:
1345: public synchronized void glFinish() {
1346: checkThread();
1347: q(CMD_FINISH, 0);
1348: qflush();
1349: }
1350:
1351: public synchronized void glFlush() {
1352: checkThread();
1353: q(CMD_FLUSH, 0);
1354: qflush();
1355: }
1356:
1357: public synchronized void glFogf(int pname, float param) {
1358: checkThread();
1359: q(CMD_FOGF, 2);
1360: q(pname);
1361: q(param);
1362: }
1363:
1364: public synchronized void glFogfv(int pname, float[] params,
1365: int offset) {
1366: checkThread();
1367: int length = GLConfiguration.glFogNumParams(pname);
1368: checkLength(params, length, offset);
1369:
1370: IglFogfv(pname, params, offset);
1371: }
1372:
1373: public synchronized void glFogfv(int pname, FloatBuffer params) {
1374: checkThread();
1375: int length = GLConfiguration.glFogNumParams(pname);
1376: checkLength(params, length);
1377:
1378: if (!isDirect(params)) {
1379: IglFogfv(pname, params.array(), offset(params));
1380: return;
1381: }
1382:
1383: q(CMD_FOGFB, 2);
1384: q(pname);
1385: q(params);
1386:
1387: qflush();
1388: }
1389:
1390: void IglFogfv(int pname, float[] params, int offset) {
1391: int n = GLConfiguration.glFogNumParams(pname);
1392:
1393: q(CMD_FOGFV, n + 2);
1394: q(n);
1395: q(pname);
1396: for (int i = 0; i < n; i++) {
1397: q(params[i + offset]);
1398: }
1399: }
1400:
1401: public synchronized void glFogx(int pname, int param) {
1402: checkThread();
1403: q(CMD_FOGX, 2);
1404: q(pname);
1405: q(param);
1406: }
1407:
1408: public synchronized void glFogxv(int pname, int[] params, int offset) {
1409: checkThread();
1410: int length = GLConfiguration.glFogNumParams(pname);
1411: checkLength(params, length, offset);
1412:
1413: IglFogxv(pname, params, offset);
1414: }
1415:
1416: public synchronized void glFogxv(int pname, IntBuffer params) {
1417: checkThread();
1418: int length = GLConfiguration.glFogNumParams(pname);
1419: checkLength(params, length);
1420:
1421: if (!isDirect(params)) {
1422: IglFogxv(pname, params.array(), offset(params));
1423: return;
1424: }
1425:
1426: q(CMD_FOGXB, 2);
1427: q(pname);
1428: q(params);
1429:
1430: qflush();
1431: }
1432:
1433: void IglFogxv(int pname, int[] params, int offset) {
1434: int n = GLConfiguration.glFogNumParams(pname);
1435:
1436: q(CMD_FOGXV, n + 2);
1437: q(n);
1438: q(pname);
1439: for (int i = 0; i < n; i++) {
1440: q(params[i + offset]);
1441: }
1442: }
1443:
1444: public synchronized void glFrontFace(int mode) {
1445: checkThread();
1446: q(CMD_FRONT_FACE, 1);
1447: q(mode);
1448: }
1449:
1450: public synchronized void glFrustumf(float left, float right,
1451: float bottom, float top, float zNear, float zFar) {
1452: checkThread();
1453: q(CMD_FRUSTUMF, 6);
1454: q(left);
1455: q(right);
1456: q(bottom);
1457: q(top);
1458: q(zNear);
1459: q(zFar);
1460: }
1461:
1462: public synchronized void glFrustumx(int left, int right,
1463: int bottom, int top, int zNear, int zFar) {
1464: checkThread();
1465: q(CMD_FRUSTUMX, 6);
1466: q(left);
1467: q(right);
1468: q(bottom);
1469: q(top);
1470: q(zNear);
1471: q(zFar);
1472: }
1473:
1474: public synchronized void glGenTextures(int n, int[] textures,
1475: int offset) {
1476: checkThread();
1477: checkLength(textures, n, offset);
1478:
1479: qflush();
1480: IglGenTextures(n, textures, offset);
1481: }
1482:
1483: public synchronized void glGenTextures(int n, IntBuffer textures) {
1484: checkThread();
1485: checkLength(textures, n);
1486:
1487: qflush();
1488: if (!isDirect(textures)) {
1489: IglGenTextures(n, textures.array(), offset(textures));
1490: return;
1491: }
1492:
1493: q(CMD_GEN_TEXTURESB, 2);
1494: q(n);
1495: q(textures);
1496:
1497: qflush();
1498: }
1499:
1500: void IglGenTextures(int n, int[] textures, int offset) {
1501: grabContext();
1502: _glGenTextures(n, textures, offset);
1503: }
1504:
1505: public synchronized void glGetBooleanv(int pname, boolean[] params,
1506: int offset) {
1507: checkThread();
1508: int length = GLConfiguration.glGetNumParams(pname);
1509: checkLength(params, length, offset);
1510:
1511: qflush();
1512:
1513: int[] iparams = new int[length];
1514: IglGetBooleanv(pname, iparams, 0, length);
1515: for (int i = 0; i < length; i++) {
1516: params[offset + i] = (iparams[i] == 1);
1517: }
1518: }
1519:
1520: public synchronized void glGetBooleanv(int pname, IntBuffer params) {
1521: checkThread();
1522: int length = GLConfiguration.glGetNumParams(pname);
1523: checkLength(params, length);
1524:
1525: qflush();
1526: if (!params.isDirect()) {
1527: IglGetBooleanv(pname, params.array(), offset(params),
1528: length);
1529: } else {
1530: IglGetBooleanv(pname, null, pointer(params), length);
1531: }
1532: }
1533:
1534: void IglGetBooleanv(int pname, int[] params, int offset, int length) {
1535: grabContext();
1536: _glGetBooleanv(pname, params, offset, length);
1537: }
1538:
1539: public synchronized void glGetIntegerv(int pname, int[] params,
1540: int offset) {
1541: checkThread();
1542: int length = GLConfiguration.glGetNumParams(pname);
1543: checkLength(params, length, offset);
1544:
1545: qflush();
1546: IglGetIntegerv(pname, params, offset, length);
1547:
1548: // Workaround for Gerbera bug, CR 6401385
1549: if (pname == GL_CULL_FACE) {
1550: params[offset] = cullFaceMode;
1551: }
1552: }
1553:
1554: public synchronized void glGetIntegerv(int pname, IntBuffer params) {
1555: checkThread();
1556: int length = GLConfiguration.glGetNumParams(pname);
1557: checkLength(params, length);
1558:
1559: qflush();
1560: if (!params.isDirect()) {
1561: int[] array = params.array();
1562: int offset = offset(params);
1563:
1564: IglGetIntegerv(pname, array, offset, length);
1565:
1566: // Workaround for Gerbera bug, CR 6401385
1567: if (pname == GL_CULL_FACE) {
1568: array[offset] = cullFaceMode;
1569: }
1570: } else {
1571: IglGetIntegerv(pname, null, pointer(params), length);
1572:
1573: // Workaround for Gerbera bug, CR 6401385
1574: if (pname == GL_CULL_FACE) {
1575: params.put(params.position(), cullFaceMode);
1576: }
1577: }
1578: }
1579:
1580: void IglGetIntegerv(int pname, int[] params, int offset, int length) {
1581: grabContext();
1582: _glGetIntegerv(pname, params, offset, length);
1583: }
1584:
1585: public synchronized int glGetError() {
1586: checkThread();
1587: qflush();
1588:
1589: grabContext();
1590: int error = _glGetError();
1591: return error;
1592: }
1593:
1594: public synchronized String glGetString(int name) {
1595: checkThread();
1596: qflush();
1597:
1598: grabContext();
1599: String s = _glGetString(name);
1600: return s;
1601: }
1602:
1603: public synchronized boolean glIsBuffer(int buffer) {
1604: checkThread();
1605: qflush();
1606:
1607: grabContext();
1608: boolean retval = GL_TRUE == _glIsBuffer(buffer);
1609: return retval;
1610: }
1611:
1612: public synchronized boolean glIsEnabled(int cap) {
1613: checkThread();
1614: qflush();
1615:
1616: grabContext();
1617: boolean retval = GL_TRUE == _glIsEnabled(cap);
1618: return retval;
1619: }
1620:
1621: public synchronized boolean glIsTexture(int texture) {
1622: checkThread();
1623: qflush();
1624:
1625: grabContext();
1626: boolean retval = false;
1627:
1628: // Woraround for Gerbera bug, see CR 6401677
1629: if (texture != 0) {
1630: retval = GL_TRUE == _glIsTexture(texture);
1631: }
1632: return retval;
1633: }
1634:
1635: public synchronized void glHint(int target, int mode) {
1636: checkThread();
1637: q(CMD_HINT, 2);
1638: q(target);
1639: q(mode);
1640: }
1641:
1642: public synchronized void glLightModelf(int pname, float param) {
1643: checkThread();
1644: q(CMD_LIGHT_MODELF, 2);
1645: q(pname);
1646: q(param);
1647: }
1648:
1649: public synchronized void glLightModelfv(int pname, float[] params,
1650: int offset) {
1651: checkThread();
1652: int length = GLConfiguration.glLightModelNumParams(pname);
1653: checkLength(params, length, offset);
1654:
1655: IglLightModelfv(pname, params, offset);
1656: }
1657:
1658: public synchronized void glLightModelfv(int pname,
1659: FloatBuffer params) {
1660: checkThread();
1661: int length = GLConfiguration.glLightModelNumParams(pname);
1662: checkLength(params, length);
1663:
1664: if (!params.isDirect()) {
1665: IglLightModelfv(pname, params.array(), offset(params));
1666: return;
1667: }
1668:
1669: q(CMD_LIGHT_MODELFB, 2);
1670: q(pname);
1671: q(params);
1672:
1673: qflush();
1674: }
1675:
1676: void IglLightModelfv(int pname, float[] params, int offset) {
1677: int n = GLConfiguration.glLightModelNumParams(pname);
1678:
1679: q(CMD_LIGHT_MODELFV, n + 2);
1680: q(n);
1681: q(pname);
1682: for (int i = 0; i < n; i++) {
1683: q(params[i + offset]);
1684: }
1685: }
1686:
1687: public synchronized void glLightModelx(int pname, int param) {
1688: checkThread();
1689: q(CMD_LIGHT_MODELX, 2);
1690: q(pname);
1691: q(param);
1692: }
1693:
1694: public synchronized void glLightModelxv(int pname, int[] params,
1695: int offset) {
1696: checkThread();
1697: int length = GLConfiguration.glLightModelNumParams(pname);
1698: checkLength(params, length, offset);
1699:
1700: IglLightModelxv(pname, params, offset);
1701: }
1702:
1703: public synchronized void glLightModelxv(int pname, IntBuffer params) {
1704: checkThread();
1705: int length = GLConfiguration.glLightModelNumParams(pname);
1706: checkLength(params, length);
1707:
1708: if (!params.isDirect()) {
1709: IglLightModelxv(pname, params.array(), offset(params));
1710: return;
1711: }
1712:
1713: q(CMD_LIGHT_MODELXB, 2);
1714: q(pname);
1715: q(params);
1716:
1717: qflush();
1718: }
1719:
1720: void IglLightModelxv(int pname, int[] params, int offset) {
1721: int n = GLConfiguration.glLightModelNumParams(pname);
1722:
1723: q(CMD_LIGHT_MODELXV, n + 2);
1724: q(n);
1725: q(pname);
1726: for (int i = 0; i < n; i++) {
1727: q(params[i + offset]);
1728: }
1729: }
1730:
1731: public synchronized void glLightf(int light, int pname, float param) {
1732: checkThread();
1733: q(CMD_LIGHTF, 3);
1734: q(light);
1735: q(pname);
1736: q(param);
1737: }
1738:
1739: public synchronized void glLightfv(int light, int pname,
1740: float[] params, int offset) {
1741: checkThread();
1742: int length = GLConfiguration.glLightNumParams(pname);
1743: checkLength(params, length, offset);
1744:
1745: IglLightfv(light, pname, params, offset);
1746: }
1747:
1748: public synchronized void glLightfv(int light, int pname,
1749: FloatBuffer params) {
1750: checkThread();
1751: int length = GLConfiguration.glLightNumParams(pname);
1752: checkLength(params, length);
1753:
1754: if (!params.isDirect()) {
1755: IglLightfv(light, pname, params.array(), offset(params));
1756: return;
1757: }
1758:
1759: q(CMD_LIGHTFB, 3);
1760: q(light);
1761: q(pname);
1762: q(params);
1763:
1764: qflush();
1765: }
1766:
1767: void IglLightfv(int light, int pname, float[] params, int offset) {
1768: int n = GLConfiguration.glLightNumParams(pname);
1769:
1770: q(CMD_LIGHTFV, n + 3);
1771: q(n);
1772: q(light);
1773: q(pname);
1774: for (int i = 0; i < n; i++) {
1775: q(params[i + offset]);
1776: }
1777: }
1778:
1779: public synchronized void glLightx(int light, int pname, int param) {
1780: checkThread();
1781: q(CMD_LIGHTX, 3);
1782: q(light);
1783: q(pname);
1784: q(param);
1785: }
1786:
1787: public synchronized void glLightxv(int light, int pname,
1788: int[] params, int offset) {
1789: checkThread();
1790: int length = GLConfiguration.glLightNumParams(pname);
1791: checkLength(params, length, offset);
1792:
1793: IglLightxv(light, pname, params, offset);
1794: }
1795:
1796: public synchronized void glLightxv(int light, int pname,
1797: IntBuffer params) {
1798: checkThread();
1799: int length = GLConfiguration.glLightNumParams(pname);
1800: checkLength(params, length);
1801:
1802: if (!params.isDirect()) {
1803: IglLightxv(light, pname, params.array(), offset(params));
1804: return;
1805: }
1806:
1807: q(CMD_LIGHTXB, 3);
1808: q(light);
1809: q(pname);
1810: q(params);
1811:
1812: qflush();
1813: }
1814:
1815: void IglLightxv(int light, int pname, int[] params, int offset) {
1816: int n = GLConfiguration.glLightNumParams(pname);
1817:
1818: q(CMD_LIGHTXV, n + 3);
1819: q(n);
1820: q(light);
1821: q(pname);
1822: for (int i = 0; i < n; i++) {
1823: q(params[i + offset]);
1824: }
1825: }
1826:
1827: public synchronized void glLineWidth(float width) {
1828: checkThread();
1829: q(CMD_LINE_WIDTH, 1);
1830: q(width);
1831: }
1832:
1833: public synchronized void glLineWidthx(int width) {
1834: checkThread();
1835: q(CMD_LINE_WIDTHX, 1);
1836: q(width);
1837: }
1838:
1839: public synchronized void glLoadIdentity() {
1840: checkThread();
1841: q(CMD_LOAD_IDENTITY, 0);
1842: }
1843:
1844: public synchronized void glLoadMatrixf(float[] m, int offset) {
1845: checkThread();
1846: checkLength(m, 16, offset);
1847:
1848: IglLoadMatrixf(m, offset);
1849: }
1850:
1851: public synchronized void glLoadMatrixf(FloatBuffer m) {
1852: checkThread();
1853: checkLength(m, 16);
1854:
1855: if (!m.isDirect()) {
1856: IglLoadMatrixf(m.array(), offset(m));
1857: return;
1858: }
1859:
1860: q(CMD_LOAD_MATRIXFB, 1);
1861: q(m);
1862:
1863: qflush();
1864: }
1865:
1866: void IglLoadMatrixf(float[] m, int offset) {
1867: q(CMD_LOAD_MATRIXF, 16);
1868: for (int i = 0; i < 16; i++) {
1869: q(m[i + offset]);
1870: }
1871: }
1872:
1873: public synchronized void glLoadMatrixx(int[] m, int offset) {
1874: checkThread();
1875: checkLength(m, 16, offset);
1876:
1877: IglLoadMatrixx(m, offset);
1878: }
1879:
1880: public synchronized void glLoadMatrixx(IntBuffer m) {
1881: checkThread();
1882: checkLength(m, 16);
1883:
1884: if (!m.isDirect()) {
1885: IglLoadMatrixx(m.array(), offset(m));
1886: return;
1887: }
1888:
1889: q(CMD_LOAD_MATRIXXB, 1);
1890: q(m);
1891:
1892: qflush();
1893: }
1894:
1895: void IglLoadMatrixx(int[] m, int offset) {
1896: q(CMD_LOAD_MATRIXX, 16);
1897: for (int i = 0; i < 16; i++) {
1898: q(m[i + offset]);
1899: }
1900: }
1901:
1902: public synchronized void glLogicOp(int opcode) {
1903: checkThread();
1904: q(CMD_LOGIC_OP, 1);
1905: q(opcode);
1906: }
1907:
1908: public synchronized void glMaterialf(int face, int pname,
1909: float param) {
1910: checkThread();
1911: q(CMD_MATERIALF, 3);
1912: q(face);
1913: q(pname);
1914: q(param);
1915: }
1916:
1917: public synchronized void glMaterialfv(int face, int pname,
1918: float[] params, int offset) {
1919: checkThread();
1920: int length = GLConfiguration.glMaterialNumParams(pname);
1921: checkLength(params, length, offset);
1922:
1923: IglMaterialfv(face, pname, params, offset);
1924: }
1925:
1926: public synchronized void glMaterialfv(int face, int pname,
1927: FloatBuffer params) {
1928: checkThread();
1929: int length = GLConfiguration.glMaterialNumParams(pname);
1930: checkLength(params, length);
1931:
1932: if (!params.isDirect()) {
1933: IglMaterialfv(face, pname, params.array(), offset(params));
1934: return;
1935: }
1936:
1937: q(CMD_MATERIALFB, 3);
1938: q(face);
1939: q(pname);
1940: q(params);
1941:
1942: qflush();
1943: }
1944:
1945: void IglMaterialfv(int face, int pname, float[] params, int offset) {
1946: int n = GLConfiguration.glMaterialNumParams(pname);
1947:
1948: q(CMD_MATERIALFV, n + 3);
1949: q(n);
1950: q(face);
1951: q(pname);
1952: for (int i = 0; i < n; i++) {
1953: q(params[i + offset]);
1954: }
1955: }
1956:
1957: public synchronized void glMaterialx(int face, int pname, int param) {
1958: checkThread();
1959: q(CMD_MATERIALX, 3);
1960: q(face);
1961: q(pname);
1962: q(param);
1963: }
1964:
1965: public synchronized void glMaterialxv(int face, int pname,
1966: int[] params, int offset) {
1967: checkThread();
1968: int length = GLConfiguration.glMaterialNumParams(pname);
1969: checkLength(params, length, offset);
1970:
1971: IglMaterialxv(face, pname, params, offset);
1972: }
1973:
1974: public synchronized void glMaterialxv(int face, int pname,
1975: IntBuffer params) {
1976: checkThread();
1977: int length = GLConfiguration.glMaterialNumParams(pname);
1978: checkLength(params, length);
1979:
1980: if (!params.isDirect()) {
1981: IglMaterialxv(face, pname, params.array(), offset(params));
1982: return;
1983: }
1984:
1985: q(CMD_MATERIALXB, 3);
1986: q(face);
1987: q(pname);
1988: q(params);
1989:
1990: qflush();
1991: }
1992:
1993: void IglMaterialxv(int face, int pname, int[] params, int offset) {
1994: int n = GLConfiguration.glMaterialNumParams(pname);
1995:
1996: q(CMD_MATERIALXV, n + 3);
1997: q(n);
1998: q(face);
1999: q(pname);
2000: for (int i = 0; i < n; i++) {
2001: q(params[i + offset]);
2002: }
2003: }
2004:
2005: public synchronized void glMatrixMode(int mode) {
2006: checkThread();
2007: q(CMD_MATRIX_MODE, 1);
2008: q(mode);
2009: }
2010:
2011: public synchronized void glMultMatrixf(float[] m, int offset) {
2012: checkThread();
2013: checkLength(m, 16, offset);
2014:
2015: IglMultMatrixf(m, offset);
2016: }
2017:
2018: public synchronized void glMultMatrixf(FloatBuffer m) {
2019: checkThread();
2020: checkLength(m, 16);
2021:
2022: if (!m.isDirect()) {
2023: IglMultMatrixf(m.array(), offset(m));
2024: return;
2025: }
2026:
2027: q(CMD_MULT_MATRIXFB, 1);
2028: q(m);
2029:
2030: qflush();
2031: }
2032:
2033: void IglMultMatrixf(float[] m, int offset) {
2034: q(CMD_MULT_MATRIXF, 16);
2035: for (int i = 0; i < 16; i++) {
2036: q(m[i + offset]);
2037: }
2038: }
2039:
2040: public synchronized void glMultMatrixx(int[] m, int offset) {
2041: checkThread();
2042: checkLength(m, 16, offset);
2043:
2044: IglMultMatrixx(m, offset);
2045: }
2046:
2047: public synchronized void glMultMatrixx(IntBuffer m) {
2048: checkThread();
2049: checkLength(m, 16);
2050:
2051: if (!m.isDirect()) {
2052: IglMultMatrixx(m.array(), offset(m));
2053: return;
2054: }
2055:
2056: q(CMD_MULT_MATRIXXB, 1);
2057: q(m);
2058:
2059: qflush();
2060: }
2061:
2062: void IglMultMatrixx(int[] m, int offset) {
2063: q(CMD_MULT_MATRIXX, 16);
2064: for (int i = 0; i < 16; i++) {
2065: q(m[i + offset]);
2066: }
2067: }
2068:
2069: public synchronized void glMultiTexCoord4f(int target, float s,
2070: float t, float r, float q) {
2071: checkThread();
2072: q(CMD_MULTI_TEXT_COORD4F, 5);
2073: q(target);
2074: q(s);
2075: q(t);
2076: q(r);
2077: q(q);
2078: }
2079:
2080: public synchronized void glMultiTexCoord4x(int target, int s,
2081: int t, int r, int q) {
2082: checkThread();
2083: q(CMD_MULTI_TEXT_COORD4X, 5);
2084: q(target);
2085: q(s);
2086: q(t);
2087: q(r);
2088: q(q);
2089: }
2090:
2091: public synchronized void glNormal3f(float nx, float ny, float nz) {
2092: checkThread();
2093: q(CMD_NORMAL3F, 3);
2094: q(nx);
2095: q(ny);
2096: q(nz);
2097: }
2098:
2099: public synchronized void glNormal3x(int nx, int ny, int nz) {
2100: checkThread();
2101: q(CMD_NORMAL3X, 3);
2102: q(nx);
2103: q(ny);
2104: q(nz);
2105: }
2106:
2107: public synchronized void glNormalPointer(int type, int stride,
2108: Buffer pointer) {
2109: checkThread();
2110: if (VBOArrayBufferBound != 0) {
2111: throw new IllegalStateException("glNormalPointer:"
2112: + Errors.VBO_ARRAY_BUFFER_BOUND);
2113: }
2114: if (!isDirect(pointer)) {
2115: throwIAE(Errors.GL_NOT_DIRECT);
2116: }
2117:
2118: if ((type == GL_BYTE || type == GL_SHORT || type == GL_FIXED || type == GL_FLOAT)
2119: && (stride >= 0)) {
2120: BufferManager.releaseBuffer(pointerBuffer[NORMAL_POINTER]);
2121: BufferManager.useBuffer(pointer);
2122:
2123: pointerBuffer[NORMAL_POINTER] = pointer;
2124: pointerSize[NORMAL_POINTER] = 3;
2125: pointerType[NORMAL_POINTER] = type;
2126: pointerStride[NORMAL_POINTER] = stride;
2127: int nbytes = bufferTypeSize(pointer);
2128: pointerRemaining[NORMAL_POINTER] = pointer.remaining()
2129: * nbytes;
2130: pointerOffset[NORMAL_POINTER] = 0;
2131: }
2132:
2133: q(CMD_NORMAL_POINTER, 3);
2134: q(type);
2135: q(stride);
2136: q(pointer);
2137:
2138: qflush();
2139: }
2140:
2141: public synchronized void glOrthof(float left, float right,
2142: float bottom, float top, float zNear, float zFar) {
2143: checkThread();
2144: q(CMD_ORTHOF, 6);
2145: q(left);
2146: q(right);
2147: q(bottom);
2148: q(top);
2149: q(zNear);
2150: q(zFar);
2151: }
2152:
2153: public synchronized void glOrthox(int left, int right, int bottom,
2154: int top, int zNear, int zFar) {
2155: checkThread();
2156: q(CMD_ORTHOX, 6);
2157: q(left);
2158: q(right);
2159: q(bottom);
2160: q(top);
2161: q(zNear);
2162: q(zFar);
2163: }
2164:
2165: public synchronized void glPixelStorei(int pname, int param) {
2166: checkThread();
2167: q(CMD_PIXEL_STOREI, 3);
2168: q(pname);
2169: q(param);
2170:
2171: /* Only update local copy if we know command will succeed */
2172: if (param == 1 || param == 2 || param == 4 || param == 8) {
2173: if (pname == GL_PACK_ALIGNMENT) {
2174: pixelStorePackAlignment = param;
2175: } else if (pname == GL_UNPACK_ALIGNMENT) {
2176: pixelStoreUnpackAlignment = param;
2177: }
2178: }
2179: }
2180:
2181: public synchronized void glPointParameterf(int pname, float param) {
2182: checkThread();
2183: q(CMD_POINT_PARAMETERF, 2);
2184: q(pname);
2185: q(param);
2186: }
2187:
2188: public synchronized void glPointParameterfv(int pname,
2189: float[] params, int offset) {
2190: checkThread();
2191: int length = GLConfiguration.glPointParameterNumParams(pname);
2192: checkLength(params, length, offset);
2193:
2194: IglPointParameterfv(pname, params, offset);
2195: }
2196:
2197: public synchronized void glPointParameterfv(int pname,
2198: FloatBuffer params) {
2199: checkThread();
2200: int length = GLConfiguration.glPointParameterNumParams(pname);
2201: checkLength(params, length);
2202:
2203: if (!params.isDirect()) {
2204: IglPointParameterfv(pname, params.array(), offset(params));
2205: return;
2206: }
2207:
2208: q(CMD_POINT_PARAMETERFB, 2);
2209: q(pname);
2210: q(params);
2211:
2212: qflush();
2213: }
2214:
2215: void IglPointParameterfv(int pname, float[] params, int offset) {
2216: int n = GLConfiguration.glPointParameterNumParams(pname);
2217:
2218: q(CMD_POINT_PARAMETERFV, n + 2);
2219: q(n);
2220: q(pname);
2221: for (int i = 0; i < n; i++) {
2222: q(params[i + offset]);
2223: }
2224: }
2225:
2226: public synchronized void glPointParameterx(int pname, int param) {
2227: checkThread();
2228: q(CMD_POINT_PARAMETERX, 2);
2229: q(pname);
2230: q(param);
2231: }
2232:
2233: public synchronized void glPointParameterxv(int pname,
2234: int[] params, int offset) {
2235: checkThread();
2236: int length = GLConfiguration.glPointParameterNumParams(pname);
2237: checkLength(params, length, offset);
2238:
2239: IglPointParameterxv(pname, params, offset);
2240: }
2241:
2242: public synchronized void glPointParameterxv(int pname,
2243: IntBuffer params) {
2244: checkThread();
2245: int length = GLConfiguration.glPointParameterNumParams(pname);
2246: checkLength(params, length);
2247:
2248: if (!params.isDirect()) {
2249: IglPointParameterxv(pname, params.array(), offset(params));
2250: return;
2251: }
2252:
2253: q(CMD_POINT_PARAMETERXB, 2);
2254: q(pname);
2255: q(params);
2256:
2257: qflush();
2258: }
2259:
2260: void IglPointParameterxv(int pname, int[] params, int offset) {
2261: int n = GLConfiguration.glPointParameterNumParams(pname);
2262:
2263: q(CMD_POINT_PARAMETERXV, n + 2);
2264: q(n);
2265: q(pname);
2266: for (int i = 0; i < n; i++) {
2267: q(params[i + offset]);
2268: }
2269: }
2270:
2271: public synchronized void glPointSize(float size) {
2272: checkThread();
2273: q(CMD_POINT_SIZE, 1);
2274: q(size);
2275: }
2276:
2277: public synchronized void glPointSizex(int size) {
2278: checkThread();
2279: q(CMD_POINT_SIZEX, 1);
2280: q(size);
2281: }
2282:
2283: public synchronized void glPolygonOffset(float factor, float units) {
2284: checkThread();
2285: q(CMD_POLYGON_OFFSET, 2);
2286: q(factor);
2287: q(units);
2288: }
2289:
2290: public synchronized void glPolygonOffsetx(int factor, int units) {
2291: checkThread();
2292: q(CMD_POLYGON_OFFSETX, 2);
2293: q(factor);
2294: q(units);
2295: }
2296:
2297: public synchronized void glPopMatrix() {
2298: checkThread();
2299: q(CMD_POP_MATRIX, 0);
2300: }
2301:
2302: public synchronized void glPushMatrix() {
2303: checkThread();
2304: q(CMD_PUSH_MATRIX, 0);
2305: }
2306:
2307: // Pad must be a power of 2
2308: private int rasterBytes(int width, int height, int format,
2309: int type, int pad) {
2310: int bytesPerPixel = GLConfiguration.formatChannels(format)
2311: * GLConfiguration.sizeOfType(type);
2312: int rowWidth = width * bytesPerPixel;
2313: // stride = rowWidth rounded up to a multiple of 'pad' bytes
2314: int stride = (rowWidth + pad - 1) & ~(pad - 1);
2315:
2316: return stride * (height - 1) + rowWidth;
2317: }
2318:
2319: public synchronized void glReadPixels(int x, int y, int width,
2320: int height, int format, int type, Buffer pixels) {
2321: checkThread();
2322: qflush();
2323:
2324: if (pixels == null) {
2325: throwIAE(Errors.GL_PIXELS_NULL);
2326: }
2327: int remaining = pixels.remaining() * bufferTypeSize(pixels);
2328: int needed = rasterBytes(width, height, format, type,
2329: pixelStorePackAlignment);
2330: if (needed > remaining) {
2331: throwIAE(Errors.NOT_ENOUGH_ROOM);
2332: }
2333:
2334: if (isDirect(pixels)) {
2335: grabContext();
2336: _glReadPixelsPtr(x, y, width, height, format, type,
2337: pointer(pixels));
2338: } else {
2339: if (pixels instanceof ByteBuffer) {
2340: ByteBuffer p = (ByteBuffer) pixels;
2341: grabContext();
2342: _glReadPixelsByte(x, y, width, height, format, type, p
2343: .array(), offset(p));
2344: } else if (pixels instanceof IntBuffer) {
2345: IntBuffer p = (IntBuffer) pixels;
2346: grabContext();
2347: _glReadPixelsInt(x, y, width, height, format, type, p
2348: .array(), offset(p));
2349: } else {
2350: throwIAE(Errors.GL_UNKNOWN_BUFFER);
2351: }
2352: }
2353: }
2354:
2355: public synchronized void glRotatef(float angle, float x, float y,
2356: float z) {
2357: checkThread();
2358: q(CMD_ROTATEF, 4);
2359: q(angle);
2360: q(x);
2361: q(y);
2362: q(z);
2363: }
2364:
2365: public synchronized void glRotatex(int angle, int x, int y, int z) {
2366: checkThread();
2367: q(CMD_ROTATEX, 4);
2368: q(angle);
2369: q(x);
2370: q(y);
2371: q(z);
2372: }
2373:
2374: public synchronized void glSampleCoverage(float value,
2375: boolean invert) {
2376: checkThread();
2377: q(CMD_SAMPLE_COVERAGE, 2);
2378: q(value);
2379: q(invert ? 1 : 0);
2380: }
2381:
2382: public synchronized void glSampleCoveragex(int value, boolean invert) {
2383: checkThread();
2384: q(CMD_SAMPLE_COVERAGEX, 2);
2385: q(value);
2386: q(invert ? 1 : 0);
2387: }
2388:
2389: public synchronized void glScalef(float x, float y, float z) {
2390: checkThread();
2391: q(CMD_SCALEF, 3);
2392: q(x);
2393: q(y);
2394: q(z);
2395: }
2396:
2397: public synchronized void glScalex(int x, int y, int z) {
2398: checkThread();
2399: q(CMD_SCALEX, 3);
2400: q(x);
2401: q(y);
2402: q(z);
2403: }
2404:
2405: public synchronized void glScissor(int x, int y, int width,
2406: int height) {
2407: checkThread();
2408: q(CMD_SCISSOR, 4);
2409: q(x);
2410: q(y);
2411: q(width);
2412: q(height);
2413: }
2414:
2415: public synchronized void glShadeModel(int mode) {
2416: checkThread();
2417: q(CMD_SHADE_MODEL, 1);
2418: q(mode);
2419: }
2420:
2421: public synchronized void glStencilFunc(int func, int ref, int mask) {
2422: checkThread();
2423: q(CMD_STENCIL_FUNC, 3);
2424: q(func);
2425: q(ref);
2426: q(mask);
2427: }
2428:
2429: public synchronized void glStencilMask(int mask) {
2430: checkThread();
2431: q(CMD_STENCIL_MASK, 2);
2432: q(mask);
2433: }
2434:
2435: public synchronized void glStencilOp(int fail, int zfail, int zpass) {
2436: checkThread();
2437: q(CMD_STENCIL_OP, 3);
2438: q(fail);
2439: q(zfail);
2440: q(zpass);
2441: }
2442:
2443: public synchronized void glTexCoordPointer(int size, int type,
2444: int stride, Buffer pointer) {
2445: checkThread();
2446: if (VBOArrayBufferBound != 0) {
2447: throw new IllegalStateException("glTexCoordPointer:"
2448: + Errors.VBO_ARRAY_BUFFER_BOUND);
2449: }
2450: if (!isDirect(pointer)) {
2451: throwIAE(Errors.GL_NOT_DIRECT);
2452: }
2453:
2454: if ((size >= 2 && size <= 4)
2455: && (type == GL_BYTE || type == GL_SHORT
2456: || type == GL_FIXED || type == GL_FLOAT)
2457: && (stride >= 0)) {
2458: BufferManager
2459: .releaseBuffer(pointerBuffer[TEX_COORD_POINTER]);
2460: BufferManager.useBuffer(pointer);
2461:
2462: pointerBuffer[TEX_COORD_POINTER] = pointer;
2463: pointerSize[TEX_COORD_POINTER] = size;
2464: pointerType[TEX_COORD_POINTER] = type;
2465: pointerStride[TEX_COORD_POINTER] = stride;
2466: int nbytes = bufferTypeSize(pointer);
2467: pointerRemaining[TEX_COORD_POINTER] = pointer.remaining()
2468: * nbytes;
2469: pointerOffset[TEX_COORD_POINTER] = 0;
2470: }
2471:
2472: q(CMD_TEX_COORD_POINTER, 4);
2473: q(size);
2474: q(type);
2475: q(stride);
2476: q(pointer);
2477:
2478: qflush();
2479: }
2480:
2481: public synchronized void glTexEnvi(int target, int pname, int param) {
2482: checkThread();
2483: q(CMD_TEX_ENVI, 3);
2484: q(target);
2485: q(pname);
2486: q(param);
2487: }
2488:
2489: public synchronized void glTexEnviv(int target, int pname,
2490: int[] params, int offset) {
2491: checkThread();
2492: int length = GLConfiguration.glTexEnvNumParams(pname);
2493: checkLength(params, length, offset);
2494:
2495: IglTexEnviv(target, pname, params, offset);
2496: }
2497:
2498: public synchronized void glTexEnviv(int target, int pname,
2499: IntBuffer params) {
2500: checkThread();
2501: int length = GLConfiguration.glTexEnvNumParams(pname);
2502: checkLength(params, length);
2503:
2504: if (!params.isDirect()) {
2505: IglTexEnviv(target, pname, params.array(), offset(params));
2506: return;
2507: }
2508:
2509: q(CMD_TEX_ENVIB, 3);
2510: q(target);
2511: q(pname);
2512: q(params);
2513:
2514: qflush();
2515: }
2516:
2517: void IglTexEnviv(int target, int pname, int[] params, int offset) {
2518: int n = GLConfiguration.glTexEnvNumParams(pname);
2519:
2520: q(CMD_TEX_ENVIV, n + 3);
2521: q(n);
2522: q(target);
2523: q(pname);
2524: for (int i = 0; i < n; i++) {
2525: q(params[i + offset]);
2526: }
2527: }
2528:
2529: public synchronized void glTexEnvf(int target, int pname,
2530: float param) {
2531: checkThread();
2532: q(CMD_TEX_ENVF, 3);
2533: q(target);
2534: q(pname);
2535: q(param);
2536: }
2537:
2538: public synchronized void glTexEnvfv(int target, int pname,
2539: float[] params, int offset) {
2540: checkThread();
2541: int length = GLConfiguration.glTexEnvNumParams(pname);
2542: checkLength(params, length, offset);
2543:
2544: IglTexEnvfv(target, pname, params, offset);
2545: }
2546:
2547: public synchronized void glTexEnvfv(int target, int pname,
2548: FloatBuffer params) {
2549: checkThread();
2550: int length = GLConfiguration.glTexEnvNumParams(pname);
2551: checkLength(params, length);
2552:
2553: if (!params.isDirect()) {
2554: IglTexEnvfv(target, pname, params.array(), offset(params));
2555: return;
2556: }
2557:
2558: q(CMD_TEX_ENVFB, 3);
2559: q(target);
2560: q(pname);
2561: q(params);
2562:
2563: qflush();
2564: }
2565:
2566: void IglTexEnvfv(int target, int pname, float[] params, int offset) {
2567: int n = GLConfiguration.glTexEnvNumParams(pname);
2568:
2569: q(CMD_TEX_ENVFV, n + 3);
2570: q(n);
2571: q(target);
2572: q(pname);
2573: for (int i = 0; i < n; i++) {
2574: q(params[i + offset]);
2575: }
2576: }
2577:
2578: public synchronized void glTexEnvx(int target, int pname, int param) {
2579: checkThread();
2580: q(CMD_TEX_ENVX, 3);
2581: q(target);
2582: q(pname);
2583: q(param);
2584: }
2585:
2586: public synchronized void glTexEnvxv(int target, int pname,
2587: int[] params, int offset) {
2588: checkThread();
2589: int length = GLConfiguration.glTexEnvNumParams(pname);
2590: checkLength(params, length, offset);
2591:
2592: IglTexEnvxv(target, pname, params, offset);
2593: }
2594:
2595: public synchronized void glTexEnvxv(int target, int pname,
2596: IntBuffer params) {
2597: checkThread();
2598: int length = GLConfiguration.glTexEnvNumParams(pname);
2599: checkLength(params, length);
2600:
2601: if (!params.isDirect()) {
2602: IglTexEnvxv(target, pname, params.array(), offset(params));
2603: return;
2604: }
2605:
2606: q(CMD_TEX_ENVXB, 3);
2607: q(target);
2608: q(pname);
2609: q(params);
2610:
2611: qflush();
2612: }
2613:
2614: void IglTexEnvxv(int target, int pname, int[] params, int offset) {
2615: int n = GLConfiguration.glTexEnvNumParams(pname);
2616:
2617: q(CMD_TEX_ENVXV, n + 3);
2618: q(n);
2619: q(target);
2620: q(pname);
2621: for (int i = 0; i < n; i++) {
2622: q(params[i + offset]);
2623: }
2624: }
2625:
2626: public synchronized void glTexImage2D(int target, int level,
2627: int internalformat, int width, int height, int border,
2628: int format, int type, Buffer pixels) {
2629: checkThread();
2630: boolean isReadOnly = false;
2631: if (!isDirect(pixels)) {
2632: pixels = createDirectCopy(pixels);
2633: isReadOnly = true;
2634: }
2635:
2636: int remaining = pixels.remaining() * bufferTypeSize(pixels);
2637: int needed = rasterBytes(width, height, format, type,
2638: pixelStoreUnpackAlignment);
2639: if (needed > remaining) {
2640: throwIAE(Errors.NOT_ENOUGH_ROOM);
2641: }
2642:
2643: q(CMD_TEX_IMAGE_2D, 9);
2644: q(target);
2645: q(level);
2646: q(internalformat);
2647: q(width);
2648: q(height);
2649: q(border);
2650: q(format);
2651: q(type);
2652: q(pixels);
2653:
2654: if (!isReadOnly) {
2655: qflush();
2656: }
2657: }
2658:
2659: public synchronized void glTexParameterf(int target, int pname,
2660: float param) {
2661: checkThread();
2662: q(CMD_TEX_PARAMETERF, 3);
2663: q(target);
2664: q(pname);
2665: q(param);
2666: }
2667:
2668: public synchronized void glTexParameterx(int target, int pname,
2669: int param) {
2670: checkThread();
2671: q(CMD_TEX_PARAMETERX, 3);
2672: q(target);
2673: q(pname);
2674: q(param);
2675: }
2676:
2677: public synchronized void glTexParameterfv(int target, int pname,
2678: float[] params, int offset) {
2679: checkThread();
2680: int length = GLConfiguration.glTexParameterNumParams(pname);
2681: checkLength(params, length, offset);
2682:
2683: IglTexParameterfv(target, pname, params, offset);
2684: }
2685:
2686: public synchronized void glTexParameterfv(int target, int pname,
2687: FloatBuffer params) {
2688: checkThread();
2689: int length = GLConfiguration.glTexParameterNumParams(pname);
2690: checkLength(params, length);
2691:
2692: if (!params.isDirect()) {
2693: IglTexParameterfv(target, pname, params.array(),
2694: offset(params));
2695: return;
2696: }
2697:
2698: q(CMD_TEX_PARAMETERFB, 3);
2699: q(target);
2700: q(pname);
2701: q(params);
2702:
2703: qflush();
2704: }
2705:
2706: void IglTexParameterfv(int target, int pname, float[] params,
2707: int offset) {
2708: int n = GLConfiguration.glTexParameterNumParams(pname);
2709:
2710: q(CMD_TEX_PARAMETERFV, n + 3);
2711: q(n);
2712: q(target);
2713: q(pname);
2714: for (int i = 0; i < n; i++) {
2715: q(params[i + offset]);
2716: }
2717: }
2718:
2719: public synchronized void glTexParameteri(int target, int pname,
2720: int param) {
2721: checkThread();
2722: q(CMD_TEX_PARAMETERI, 3);
2723: q(target);
2724: q(pname);
2725: q(param);
2726: }
2727:
2728: public synchronized void glTexParameteriv(int target, int pname,
2729: int[] params, int offset) {
2730: checkThread();
2731: int length = GLConfiguration.glTexParameterNumParams(pname);
2732: checkLength(params, length, offset);
2733:
2734: IglTexParameteriv(target, pname, params, offset);
2735: }
2736:
2737: public synchronized void glTexParameteriv(int target, int pname,
2738: IntBuffer params) {
2739: checkThread();
2740: int length = GLConfiguration.glTexParameterNumParams(pname);
2741: checkLength(params, length);
2742:
2743: if (!params.isDirect()) {
2744: IglTexParameteriv(target, pname, params.array(),
2745: offset(params));
2746: return;
2747: }
2748:
2749: q(CMD_TEX_PARAMETERIB, 3);
2750: q(target);
2751: q(pname);
2752: q(params);
2753:
2754: qflush();
2755: }
2756:
2757: void IglTexParameteriv(int target, int pname, int[] params,
2758: int offset) {
2759: int n = GLConfiguration.glTexParameterNumParams(pname);
2760:
2761: q(CMD_TEX_PARAMETERIV, n + 3);
2762: q(n);
2763: q(target);
2764: q(pname);
2765: for (int i = 0; i < n; i++) {
2766: q(params[i + offset]);
2767: }
2768: }
2769:
2770: public synchronized void glTexParameterxv(int target, int pname,
2771: int[] params, int offset) {
2772: checkThread();
2773: int length = GLConfiguration.glTexParameterNumParams(pname);
2774: checkLength(params, length, offset);
2775:
2776: IglTexParameterxv(target, pname, params, offset);
2777: }
2778:
2779: public synchronized void glTexParameterxv(int target, int pname,
2780: IntBuffer params) {
2781: checkThread();
2782: int length = GLConfiguration.glTexParameterNumParams(pname);
2783: checkLength(params, length);
2784:
2785: if (!params.isDirect()) {
2786: IglTexParameterxv(target, pname, params.array(),
2787: offset(params));
2788: return;
2789: }
2790:
2791: q(CMD_TEX_PARAMETERXB, 3);
2792: q(target);
2793: q(pname);
2794: q(params);
2795:
2796: qflush();
2797: }
2798:
2799: void IglTexParameterxv(int target, int pname, int[] params,
2800: int offset) {
2801: int n = GLConfiguration.glTexParameterNumParams(pname);
2802:
2803: q(CMD_TEX_PARAMETERXV, n + 3);
2804: q(n);
2805: q(target);
2806: q(pname);
2807: for (int i = 0; i < n; i++) {
2808: q(params[i + offset]);
2809: }
2810: }
2811:
2812: public synchronized void glTexSubImage2D(int target, int level,
2813: int xoffset, int yoffset, int width, int height,
2814: int format, int type, Buffer pixels) {
2815: checkThread();
2816: if ((pixels instanceof ShortBuffer)
2817: || (pixels instanceof IntBuffer)) {
2818: throwIAE(Errors.GL_PIXELS_NOT_SHORT_OR_INT);
2819: }
2820:
2821: boolean isReadOnly = false;
2822: if (!isDirect(pixels)) {
2823: pixels = createDirectCopy(pixels);
2824: isReadOnly = true;
2825: }
2826:
2827: int remaining = pixels.remaining() * bufferTypeSize(pixels);
2828: int needed = rasterBytes(width, height, format, type,
2829: pixelStoreUnpackAlignment);
2830: if (needed > remaining) {
2831: throwIAE(Errors.NOT_ENOUGH_ROOM);
2832: }
2833:
2834: q(CMD_TEX_SUB_IMAGE_2D, 9);
2835: q(target);
2836: q(level);
2837: q(xoffset);
2838: q(yoffset);
2839: q(width);
2840: q(height);
2841: q(format);
2842: q(type);
2843: q(pixels);
2844:
2845: if (!isReadOnly) {
2846: qflush();
2847: }
2848: }
2849:
2850: public synchronized void glTranslatef(float x, float y, float z) {
2851: checkThread();
2852: q(CMD_TRANSLATEF, 3);
2853: q(x);
2854: q(y);
2855: q(z);
2856: }
2857:
2858: public synchronized void glTranslatex(int x, int y, int z) {
2859: checkThread();
2860: q(CMD_TRANSLATEX, 3);
2861: q(x);
2862: q(y);
2863: q(z);
2864: }
2865:
2866: // Utility to return the number of bytes per Buffer element
2867: int bufferTypeSize(Buffer pointer) {
2868: if (pointer instanceof ByteBuffer) {
2869: return 1;
2870: } else if (pointer instanceof ShortBuffer) {
2871: return 2;
2872: } else if (pointer instanceof IntBuffer
2873: || pointer instanceof FloatBuffer) {
2874: return 4;
2875: } else {
2876: throw new IllegalArgumentException(
2877: "Unknown Buffer subclass!");
2878: }
2879: }
2880:
2881: public synchronized void glVertexPointer(int size, int type,
2882: int stride, Buffer pointer) {
2883: checkThread();
2884: if (VBOArrayBufferBound != 0) {
2885: throw new IllegalStateException("glVertexPointer:"
2886: + Errors.VBO_ARRAY_BUFFER_BOUND);
2887: }
2888: if (!isDirect(pointer)) {
2889: throwIAE(Errors.GL_NOT_DIRECT);
2890: }
2891:
2892: // Only record details if this is a legal operation
2893: if ((size >= 2 && size <= 4)
2894: && (type == GL_BYTE || type == GL_SHORT
2895: || type == GL_FIXED || type == GL_FLOAT)
2896: && (stride >= 0)) {
2897: BufferManager.releaseBuffer(pointerBuffer[VERTEX_POINTER]);
2898: BufferManager.useBuffer(pointer);
2899:
2900: pointerBuffer[VERTEX_POINTER] = pointer;
2901: pointerSize[VERTEX_POINTER] = size;
2902: pointerType[VERTEX_POINTER] = type;
2903: pointerStride[VERTEX_POINTER] = stride;
2904: int nbytes = bufferTypeSize(pointer);
2905: pointerRemaining[VERTEX_POINTER] = pointer.remaining()
2906: * nbytes;
2907: pointerOffset[VERTEX_POINTER] = 0;
2908: }
2909:
2910: q(CMD_VERTEX_POINTER, 4);
2911: q(size);
2912: q(type);
2913: q(stride);
2914: q(pointer);
2915:
2916: qflush();
2917: }
2918:
2919: public synchronized void glViewport(int x, int y, int width,
2920: int height) {
2921: checkThread();
2922: q(CMD_VIEWPORT, 4);
2923: q(x);
2924: q(y);
2925: q(width);
2926: q(height);
2927: }
2928:
2929: // OES_query_matrix
2930:
2931: public synchronized int glQueryMatrixxOES(int[] mantissa,
2932: int mantissaOffset, int[] exponent, int exponentOffset) {
2933: checkThread();
2934: if (!GLConfiguration.supports_OES_query_matrix) {
2935: throw new UnsupportedOperationException(
2936: Errors.GL_QUERY_MATRIX_UNSUPPORTED);
2937: }
2938: checkLength(mantissa, 16, mantissaOffset);
2939: checkLength(exponent, 16, exponentOffset);
2940:
2941: qflush();
2942:
2943: grabContext();
2944: int retval = _glQueryMatrixxOES(mantissa, mantissaOffset,
2945: exponent, exponentOffset);
2946: return retval;
2947: }
2948:
2949: // VBO Support
2950:
2951: int VBOArrayBufferBound = 0;
2952: int VBOElementArrayBufferBound = 0;
2953:
2954: // buffer ID (Integer) -> size (Integer)
2955: Hashtable bufferSize = new Hashtable();
2956:
2957: // buffer ID (Integer) -> indices (int[])
2958: Hashtable bufferIndices = new Hashtable();
2959:
2960: // Set of currently existing buffers
2961: // Entries have the form (Integer -> Object)
2962: // There is an entry for each currently valid buffer ID
2963: // The value is not used, only the key set
2964: Hashtable VBOBuffersTable = new Hashtable();
2965:
2966: // Sizes of currently existing buffers
2967: // Entries have the form (Integer -> Integer)
2968: // There is an entry for each currently valid buffer ID
2969: Hashtable VBOBufferSizeTable = new Hashtable();
2970:
2971: // Copy of currently existing index buffers
2972: // Entries have the form (Integer -> int[])
2973: // There is an entry for each currently valid buffer ID
2974: Hashtable VBOBufferIndicesTable = new Hashtable();
2975:
2976: // Adds an entry for a buffer, initially with size 0
2977: void addBuffer(int buffer) {
2978: if (DEBUG_MEM) {
2979: System.out.println("addBuffer " + buffer);
2980: }
2981: if (buffer != 0) {
2982: Integer key = new Integer(buffer);
2983: VBOBuffersTable.put(key, new Object());
2984: VBOBufferSizeTable.put(key, new Integer(0));
2985: VBOBufferIndicesTable.put(key, new byte[0]);
2986: }
2987: }
2988:
2989: // Deletes an entry for a buffer
2990: void removeBuffer(int buffer) {
2991: if (DEBUG_MEM) {
2992: System.out.println("removeBuffer " + buffer);
2993: }
2994: if (buffer != 0) {
2995: Integer key = new Integer(buffer);
2996: VBOBuffersTable.remove(key);
2997: VBOBufferSizeTable.remove(key);
2998: VBOBufferIndicesTable.remove(key);
2999: }
3000: }
3001:
3002: // Returns true if there is a buffer with the given ID
3003: boolean bufferExists(int buffer) {
3004: return (buffer == 0)
3005: || VBOBuffersTable.containsKey(new Integer(buffer));
3006: }
3007:
3008: private Integer key(int target) {
3009: if (target == GL11.GL_ARRAY_BUFFER) {
3010: return new Integer(VBOArrayBufferBound);
3011: } else if (target == GL11.GL_ELEMENT_ARRAY_BUFFER) {
3012: return new Integer(VBOElementArrayBufferBound);
3013: } else {
3014: throw new IllegalArgumentException("target = " + target);
3015: }
3016: }
3017:
3018: // Sets the size of the current buffer for the given target
3019: void setBufferSize(int target, int size) {
3020: if (DEBUG_MEM) {
3021: System.out.println("setBufferSize " + target + " " + size);
3022: }
3023:
3024: Integer key = key(target);
3025: if (target == GL11.GL_ELEMENT_ARRAY_BUFFER) {
3026: if (DEBUG_MEM) {
3027: System.out.print("setBufferSize: allocating " + size);
3028: }
3029: VBOBufferIndicesTable.put(key, new byte[size]);
3030: if (DEBUG_MEM) {
3031: System.out.println(": done");
3032: }
3033: }
3034: VBOBufferSizeTable.put(key, new Integer(size));
3035: }
3036:
3037: int getBufferSize(int target) {
3038: Integer key = key(target);
3039:
3040: Object o = VBOBufferSizeTable.get(key);
3041: if (o != null) {
3042: return ((Integer) o).intValue();
3043: } else {
3044: throw new IllegalStateException("No VBO active for target!");
3045: }
3046: }
3047:
3048: byte[] getBufferIndices() {
3049: Integer key = key(GL11.GL_ELEMENT_ARRAY_BUFFER);
3050:
3051: Object o = VBOBufferIndicesTable.get(key);
3052: if (o != null) {
3053: return (byte[]) o;
3054: } else {
3055: throw new IllegalStateException("No VBO active for target!");
3056: }
3057: }
3058:
3059: // Records the index data where it can be used for bounds
3060: // checking in glDrawElements.
3061: void bufferIndexData(Buffer data, int offset, int size,
3062: boolean removeOldData) {
3063: Integer key = new Integer(VBOElementArrayBufferBound);
3064: byte[] array;
3065:
3066: Object o = VBOBufferIndicesTable.get(key);
3067: if (o == null || removeOldData) {
3068: array = new byte[offset + size];
3069: } else {
3070: array = (byte[]) o;
3071: if (array.length < offset + size) {
3072: byte[] narray = new byte[offset + size];
3073: System.arraycopy(narray, 0, array, 0, offset + size);
3074: array = narray;
3075: }
3076: }
3077:
3078: // Copy bytes from 'data' into 'array'
3079: BufferManager.getBytes(data, offset, array, offset, size);
3080: // (Re-)store the index data
3081: VBOBufferIndicesTable.put(key, array);
3082: }
3083:
3084: // End VBO Support
3085:
3086: public synchronized void dispose() {
3087: glFinish();
3088: this .context = null;
3089: }
3090:
3091: public GL10Impl(EGLContext context) {
3092: this.context = context;
3093: }
3094: }
|