jdk/src/share/classes/sun/java2d/pipe/RenderBuffer.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 2696 1189480fe090
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.java2d.pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The RenderBuffer class is a simplified, high-performance, Unsafe wrapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * used for buffering rendering operations in a single-threaded rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * environment.  It's functionality is similar to the ByteBuffer and related
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * NIO classes.  However, the methods in this class perform little to no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * alignment or bounds checks for performance reasons.  Therefore, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * the caller's responsibility to ensure that all put() calls are properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * aligned and within bounds:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *   - int and float values must be aligned on 4-byte boundaries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   - long and double values must be aligned on 8-byte boundaries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This class only includes the bare minimum of methods to support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * single-threaded rendering.  For example, there is no put(double[]) method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * because we currently have no need for such a method in the STR classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class RenderBuffer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * These constants represent the size of various data types (in bytes).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected static final long SIZEOF_BYTE   = 1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    protected static final long SIZEOF_SHORT  = 2L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected static final long SIZEOF_INT    = 4L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected static final long SIZEOF_FLOAT  = 4L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected static final long SIZEOF_LONG   = 8L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected static final long SIZEOF_DOUBLE = 8L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Represents the number of elements at which we have empirically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * determined that the average cost of a JNI call exceeds the expense
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * of an element by element copy.  In other words, if the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * elements in an array to be copied exceeds this value, then we should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * use the copyFromArray() method to complete the bulk put operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * (This value can be adjusted if the cost of JNI downcalls is reduced
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * in a future release.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final int COPY_FROM_ARRAY_THRESHOLD = 28;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected final Unsafe unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected final long baseAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected final long endAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected long curAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected final int capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected RenderBuffer(int numBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        unsafe = Unsafe.getUnsafe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        curAddress = baseAddress = unsafe.allocateMemory(numBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        endAddress = baseAddress + numBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        capacity = numBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Allocates a fresh buffer using the machine endianness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static RenderBuffer allocate(int numBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return new RenderBuffer(numBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Returns the base address of the underlying memory buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public final long getAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return baseAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Copies length bytes from the Java-level srcArray to the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * memory located at dstAddr.  Note that this method performs no bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * checking.  Verification that the copy will not result in memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * corruption should be done by the caller prior to invocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param srcArray the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param srcPos the starting position of the source array (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param dstAddr pointer to the destination block of native memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param length the number of bytes to copy from source to destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static native void copyFromArray(Object srcArray, long srcPos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                             long dstAddr, long length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * The behavior (and names) of the following methods are nearly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * identical to their counterparts in the various NIO Buffer classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public final int capacity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public final int remaining() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return (int)(endAddress - curAddress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public final int position() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return (int)(curAddress - baseAddress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public final void position(long numBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        curAddress = baseAddress + numBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public final void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        curAddress = baseAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * putByte() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public final RenderBuffer putByte(byte x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        unsafe.putByte(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        curAddress += SIZEOF_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public RenderBuffer put(byte[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public RenderBuffer put(byte[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            long offsetInBytes = offset * SIZEOF_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            long lengthInBytes = length * SIZEOF_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            copyFromArray(x, offsetInBytes, curAddress, lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                putByte(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * putShort() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public final RenderBuffer putShort(short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        // assert (position() % SIZEOF_SHORT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        unsafe.putShort(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        curAddress += SIZEOF_SHORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public RenderBuffer put(short[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public RenderBuffer put(short[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // assert (position() % SIZEOF_SHORT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            long offsetInBytes = offset * SIZEOF_SHORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            long lengthInBytes = length * SIZEOF_SHORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            copyFromArray(x, offsetInBytes, curAddress, lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                putShort(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * putInt() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public final RenderBuffer putInt(int pos, int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // assert (baseAddress + pos % SIZEOF_INT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        unsafe.putInt(baseAddress + pos, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public final RenderBuffer putInt(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // assert (position() % SIZEOF_INT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        unsafe.putInt(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        curAddress += SIZEOF_INT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public RenderBuffer put(int[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public RenderBuffer put(int[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // assert (position() % SIZEOF_INT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            long offsetInBytes = offset * SIZEOF_INT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            long lengthInBytes = length * SIZEOF_INT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            copyFromArray(x, offsetInBytes, curAddress, lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                putInt(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * putFloat() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public final RenderBuffer putFloat(float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        // assert (position() % SIZEOF_FLOAT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        unsafe.putFloat(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        curAddress += SIZEOF_FLOAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public RenderBuffer put(float[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public RenderBuffer put(float[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // assert (position() % SIZEOF_FLOAT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            long offsetInBytes = offset * SIZEOF_FLOAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            long lengthInBytes = length * SIZEOF_FLOAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            copyFromArray(x, offsetInBytes, curAddress, lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                putFloat(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * putLong() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public final RenderBuffer putLong(long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // assert (position() % SIZEOF_LONG == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        unsafe.putLong(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        curAddress += SIZEOF_LONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public RenderBuffer put(long[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public RenderBuffer put(long[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        // assert (position() % SIZEOF_LONG == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            long offsetInBytes = offset * SIZEOF_LONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            long lengthInBytes = length * SIZEOF_LONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            copyFromArray(x, offsetInBytes, curAddress, lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                putLong(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * putDouble() method(s)...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public final RenderBuffer putDouble(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // assert (position() % SIZEOF_DOUBLE == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        unsafe.putDouble(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        curAddress += SIZEOF_DOUBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
}