JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
GLBufferStorage.java
Go to the documentation of this file.
1/**
2 * Copyright 2014 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl;
29
30import java.nio.Buffer;
31import java.nio.ByteBuffer;
32import java.nio.IntBuffer;
33
34/**
35 * OpenGL buffer storage object reflecting it's
36 * <ul>
37 * <li>storage size</li>
38 * <li>storage memory if mapped</li>
39 * <li>mutable usage or immutable flags</li>
40 * </ul>
41 * <p>
42 * Buffer storage is created via:
43 * <ul>
44 * <li>{@link GL#glBufferData(int, long, java.nio.Buffer, int)} - storage creation via target</li>
45 * <li>{@link GL2#glNamedBufferDataEXT(int, long, java.nio.Buffer, int)} - storage creation, direct</li>
46 * <li>{@link GL4#glNamedBufferData(int, long, java.nio.Buffer, int)} - storage creation, direct</li>
47 * <li>{@link GL4#glBufferStorage(int, long, Buffer, int)} - storage creation via target</li>
48 * <li>{@link GL4#glNamedBufferStorage(int, long, Buffer, int)} - storage creation, direct</li>
49 * </ul>
50 * Note that storage <i>recreation</i> as mentioned above also invalidate a previous storage instance,
51 * i.e. disposed the buffer's current storage if exist and attaches a new storage instance.
52 * </p>
53 * <p>
54 * Buffer storage is disposed via:
55 * <ul>
56 * <li>{@link GL#glDeleteBuffers(int, IntBuffer)} - explicit, direct, via {@link #notifyBuffersDeleted(int, IntBuffer)} or {@link #notifyBuffersDeleted(int, int[], int)}</li>
57 * <li>{@link GL#glBufferData(int, long, java.nio.Buffer, int)} - storage recreation via target</li>
58 * <li>{@link GL2#glNamedBufferDataEXT(int, long, java.nio.Buffer, int)} - storage recreation, direct</li>
59 * <li>{@link GL4#glNamedBufferData(int, long, java.nio.Buffer, int)} - storage recreation, direct</li>
60 * <li>{@link GL4#glBufferStorage(int, long, Buffer, int)} - storage recreation via target</li>
61 * <li>{@link GL4#glNamedBufferStorage(int, long, Buffer, int)} - storage recreation, direct</li>
62 * </ul>
63 * </p>
64 * <p>
65 * GL buffer storage is mapped via
66 * <ul>
67 * <li>{@link GL#mapBuffer(int, int)}</li>
68 * <li>{@link GL#mapBufferRange(int, long, long, int)}</li>
69 * <li>{@link GL2#mapNamedBufferEXT(int, int)}</li>
70 * <li>{@link GL2#mapNamedBufferRangeEXT(int, long, long, int)}</li>
71 * <li>{@link GL4#mapNamedBuffer(int, int)}</li>
72 * <li>{@link GL4#mapNamedBufferRange(int, long, long, int)}</li>
73 * </ul>
74 * </p>
75 * <p>
76 * GL buffer storage is unmapped via
77 * <ul>
78 * <li>{@link GL#glDeleteBuffers(int, IntBuffer)} - buffer deletion</li>
79 * <li>{@link GL#glUnmapBuffer(int)} - explicit via target</li>
80 * <li>{@link GL2#glUnmapNamedBufferEXT(int)} - explicit direct</li>
81 * <li>{@link GL4#glUnmapNamedBuffer(int)} - explicit direct</li>
82 * <li>{@link GL#glBufferData(int, long, java.nio.Buffer, int)} - storage recreation via target</li>
83 * <li>{@link GL2#glNamedBufferDataEXT(int, long, java.nio.Buffer, int)} - storage recreation, direct</li>
84 * <li>{@link GL4#glNamedBufferData(int, long, java.nio.Buffer, int)} - storage recreation, direct</li>
85 * <li>{@link GL4#glBufferStorage(int, long, Buffer, int)} - storage creation via target</li>
86 * <li>{@link GL4#glNamedBufferStorage(int, long, Buffer, int)} - storage creation, direct</li>
87 * </ul>
88 * </p>
89 */
90public abstract class GLBufferStorage {
91 private final int name;
92 private /* final */ long size;
93 private /* final */ int mutableUsage;
94 private /* final */ int immutableFlags;
95 private ByteBuffer mappedBuffer;
96
97 protected GLBufferStorage(final int name, final long size, final int mutableUsage, final int immutableFlags) {
98 this.name = name;
99 this.size = size;
100 this.mutableUsage = mutableUsage;
101 this.immutableFlags = immutableFlags;
102 this.mappedBuffer = null;
103 }
104
105 protected void reset(final long size, final int mutableUsage, final int immutableFlags) {
106 this.size = size;
107 this.mutableUsage = mutableUsage;
108 this.immutableFlags = immutableFlags;
109 this.mappedBuffer = null;
110 }
111 protected void setMappedBuffer(final ByteBuffer buffer) {
112 this.mappedBuffer = buffer;
113 }
114
115 /** Return the buffer name */
116 public final int getName() { return name; }
117
118 /** Return the buffer's storage size. */
119 public final long getSize() { return size; }
120
121 /**
122 * Returns <code>true</code> if buffer's storage is mutable, i.e.
123 * created via {@link GL#glBufferData(int, long, java.nio.Buffer, int)}.
124 * <p>
125 * Returns <code>false</code> if buffer's storage is immutable, i.e.
126 * created via {@link GL4#glBufferStorage(int, long, Buffer, int)}.
127 * </p>
128 * @return
129 */
130 public final boolean isMutableStorage() { return 0 != mutableUsage; }
131
132 /**
133 * Returns the mutable storage usage or 0 if storage is not {@link #isMutableStorage() mutable}.
134 */
135 public final int getMutableUsage() { return mutableUsage; }
136
137 /**
138 * Returns the immutable storage flags, invalid if storage is {@link #isMutableStorage() mutable}.
139 */
140 public final int getImmutableFlags() { return immutableFlags; }
141
142 /**
143 * Returns the mapped ByteBuffer, or null if not mapped.
144 * Mapping may occur via:
145 * <ul>
146 * <li>{@link GL#glMapBuffer(int, int)}</li>
147 * <li>{@link GL#glMapBufferRange(int, long, long, int)}</li>
148 * <li>{@link GL2#glMapNamedBufferEXT(int, int)}</li>
149 * <li>{@link GL2#glMapNamedBufferRangeEXT(int, long, long, int)}
150 * </ul>
151 */
152 public final ByteBuffer getMappedBuffer() { return mappedBuffer; }
153
154 public final String toString() {
155 return toString(false);
156 }
157 public final String toString(final boolean skipMappedBuffer) {
158 final String s0;
159 if( isMutableStorage() ) {
160 s0 = String.format("%s[name %s, size %d, mutable usage 0x%X", msgClazzName, name, size, mutableUsage);
161 } else {
162 s0 = String.format("%s[name %s, size %d, immutable flags 0x%X", msgClazzName, name, size, immutableFlags);
163 }
164 if(skipMappedBuffer) {
165 return s0+"]";
166 } else {
167 return s0+", mapped "+mappedBuffer+"]";
168 }
169 }
170 private static final String msgClazzName = "GLBufferStorage";
171}
OpenGL buffer storage object reflecting it's.
final ByteBuffer getMappedBuffer()
Returns the mapped ByteBuffer, or null if not mapped.
final int getImmutableFlags()
Returns the immutable storage flags, invalid if storage is mutable.
final int getName()
Return the buffer name.
void reset(final long size, final int mutableUsage, final int immutableFlags)
final boolean isMutableStorage()
Returns true if buffer's storage is mutable, i.e.
final long getSize()
Return the buffer's storage size.
void setMappedBuffer(final ByteBuffer buffer)
final int getMutableUsage()
Returns the mutable storage usage or 0 if storage is not mutable.
GLBufferStorage(final int name, final long size, final int mutableUsage, final int immutableFlags)
final String toString(final boolean skipMappedBuffer)