From ee1587b361cfa9be17e1829f1d4d40e6400cf28f Mon Sep 17 00:00:00 2001 From: Germain AUBERT Date: Tue, 23 Feb 2021 21:52:27 +0100 Subject: [PATCH 1/5] avoid implicit update when retrieve vertices and indices buffers fixes #6430 --- CHANGES | 1 + .../graphics/glutils/IndexBufferObject.java | 16 ++++--- .../graphics/glutils/VertexBufferObject.java | 8 ++++ .../glutils/VertexBufferObjectWithVAO.java | 8 ++++ .../bullet/collision/btIndexedMesh.java | 3 +- gdx/src/com/badlogic/gdx/graphics/Mesh.java | 47 ++++++++++++------- .../gdx/graphics/g2d/SpriteBatch.java | 4 +- .../gdx/graphics/g2d/SpriteCache.java | 18 +++---- .../com/badlogic/gdx/graphics/g3d/Model.java | 8 ++-- .../gdx/graphics/glutils/IndexArray.java | 15 +++--- .../graphics/glutils/IndexBufferObject.java | 16 ++++--- .../glutils/IndexBufferObjectSubData.java | 16 ++++--- .../gdx/graphics/glutils/IndexData.java | 11 ++++- .../gdx/graphics/glutils/VertexArray.java | 7 +++ .../graphics/glutils/VertexBufferObject.java | 8 ++++ .../glutils/VertexBufferObjectSubData.java | 8 ++++ .../glutils/VertexBufferObjectWithVAO.java | 8 ++++ .../gdx/graphics/glutils/VertexData.java | 10 +++- .../gdx/tests/VBOWithVAOPerformanceTest.java | 7 +++ .../tests/VertexBufferObjectShaderTest.java | 2 +- .../tests/bullet/ConvexHullDistanceTest.java | 2 +- .../gdx/tests/bullet/ConvexHullTest.java | 2 +- .../gdx/tests/bullet/SoftBodyTest.java | 14 +++--- .../gdx/tests/bullet/SoftMeshTest.java | 8 ++-- .../gdx/tests/bullet/TriangleRaycastTest.java | 6 +-- 25 files changed, 170 insertions(+), 83 deletions(-) diff --git a/CHANGES b/CHANGES index e315ff4f885..a9b08430aae 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ - [BREAKING CHANGE] WidgetGroup#hit first validates the layout. - [BREAKING CHANGE] Cell getters return object wrapper instead of primitives. - [BREAKING CHANGE] MeshPartBuilder#lastIndex now returns int instead of short. +- [BREAKING CHANGE] Mesh#getVerticesBuffer, Mesh#getIndicesBuffer, VertexData#getBuffer, and IndexData#getBuffer are deprecated in favor to new methods with boolean parameter. If you subclassed some of these classes, you need to implement the new methods. - iOS: Add new MobiVM MetalANGLE backend - API Addition: Added Haptics API with 4 different Input#vibrate() methods with complete Android and iOS implementations. - Fix: Fixed Android and iOS touch cancelled related issues, see #6871. diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java index 038e9d90132..e879153329b 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java @@ -136,18 +136,20 @@ public void updateIndices (int targetOffset, short[] indices, int offset, int co } } - /** - *

- * Returns the underlying ShortBuffer. If you modify the buffer contents they wil be uploaded on the call to {@link #bind()}. - * If you need immediate uploading use {@link #setIndices(short[], int, int)}. - *

- * - * @return the underlying short buffer. */ + /** @deprecated use {@link #getBuffer(boolean)} instead */ + @Override + @Deprecated public ShortBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public ShortBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Binds this IndexBufferObject for rendering with glDrawElements. */ public void bind () { if (bufferHandle == 0) throw new GdxRuntimeException("No buffer allocated!"); diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java index 99f271d359f..fddb8ff63f3 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java @@ -96,12 +96,20 @@ public int getNumMaxVertices () { return buffer.capacity() / (attributes.vertexSize / 4); } + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + private void bufferChanged () { if (isBound) { Gdx.gl20.glBufferData(GL20.GL_ARRAY_BUFFER, buffer.limit(), buffer, usage); diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObjectWithVAO.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObjectWithVAO.java index 77cb6a705a6..28b7c94298c 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObjectWithVAO.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObjectWithVAO.java @@ -83,12 +83,20 @@ public int getNumMaxVertices () { return buffer.capacity() * 4 / attributes.vertexSize; } + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + private void bufferChanged () { if (isBound) { Gdx.gl20.glBufferData(GL20.GL_ARRAY_BUFFER, buffer.limit(), buffer, usage); diff --git a/extensions/gdx-bullet/jni/swig-src/collision/com/badlogic/gdx/physics/bullet/collision/btIndexedMesh.java b/extensions/gdx-bullet/jni/swig-src/collision/com/badlogic/gdx/physics/bullet/collision/btIndexedMesh.java index 8629abd2b0c..78d02d74886 100644 --- a/extensions/gdx-bullet/jni/swig-src/collision/com/badlogic/gdx/physics/bullet/collision/btIndexedMesh.java +++ b/extensions/gdx-bullet/jni/swig-src/collision/com/badlogic/gdx/physics/bullet/collision/btIndexedMesh.java @@ -172,8 +172,7 @@ public void set (final Object tag, final Mesh mesh, int offset, int count) { if (posAttr == null) throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh doesn't have a position attribute"); - set(tag, mesh.getVerticesBuffer(), mesh.getVertexSize(), mesh.getNumVertices(), posAttr.offset, mesh.getIndicesBuffer(), - offset, count); + set(tag, mesh.getVerticesBuffer(false), mesh.getVertexSize(), mesh.getNumVertices(), posAttr.offset, mesh.getIndicesBuffer(false), offset, count); } /** Convenience method to set this btIndexedMesh to the specified vertex and index data. The specified data must be indexed and diff --git a/gdx/src/com/badlogic/gdx/graphics/Mesh.java b/gdx/src/com/badlogic/gdx/graphics/Mesh.java index 0e7550ebb79..b51d8ab0c33 100644 --- a/gdx/src/com/badlogic/gdx/graphics/Mesh.java +++ b/gdx/src/com/badlogic/gdx/graphics/Mesh.java @@ -389,10 +389,10 @@ public float[] getVertices (int srcOffset, int count, float[] vertices, int dest throw new IndexOutOfBoundsException(); if ((vertices.length - destOffset) < count) throw new IllegalArgumentException( "not enough room in vertices array, has " + vertices.length + " floats, needs " + count); - int pos = getVerticesBuffer().position(); - ((Buffer)getVerticesBuffer()).position(srcOffset); - getVerticesBuffer().get(vertices, destOffset, count); - ((Buffer)getVerticesBuffer()).position(pos); + int pos = getVerticesBuffer(false).position(); + ((Buffer) getVerticesBuffer(false)).position(srcOffset); + getVerticesBuffer(false).get(vertices, destOffset, count); + ((Buffer) getVerticesBuffer(false)).position(pos); return vertices; } @@ -454,10 +454,10 @@ public void getIndices (int srcOffset, int count, short[] indices, int destOffse "Invalid range specified, offset: " + srcOffset + ", count: " + count + ", max: " + max); if ((indices.length - destOffset) < count) throw new IllegalArgumentException( "not enough room in indices array, has " + indices.length + " shorts, needs " + count); - int pos = getIndicesBuffer().position(); - ((Buffer)getIndicesBuffer()).position(srcOffset); - getIndicesBuffer().get(indices, destOffset, count); - ((Buffer)getIndicesBuffer()).position(pos); + int pos = getIndicesBuffer(false).position(); + ((Buffer) getIndicesBuffer(false)).position(srcOffset); + getIndicesBuffer(false).get(indices, destOffset, count); + ((Buffer) getIndicesBuffer(false)).position(pos); } /** @return the number of defined indices */ @@ -617,7 +617,7 @@ public void render (ShaderProgram shader, int primitiveType, int offset, int cou if (isVertexArray) { if (indices.getNumIndices() > 0) { - ShortBuffer buffer = indices.getBuffer(); + ShortBuffer buffer = indices.getBuffer(false); int oldPosition = buffer.position(); int oldLimit = buffer.limit(); ((Buffer)buffer).position(offset); @@ -679,9 +679,15 @@ public VertexAttributes getVertexAttributes () { return vertices.getAttributes(); } - /** @return the backing FloatBuffer holding the vertices. Does not have to be a direct buffer on Android! */ + /** @return the backing FloatBuffer holding the vertices. Does not have to be a direct buffer on Android! + * @deprecated use {@link #getVerticesBuffer(boolean)} instead */ + @Deprecated public FloatBuffer getVerticesBuffer () { - return vertices.getBuffer(); + return vertices.getBuffer(true); + } + + public FloatBuffer getVerticesBuffer (boolean forWriting) { + return vertices.getBuffer(forWriting); } /** Calculates the {@link BoundingBox} of the vertices contained in this mesh. In case no vertices are defined yet a @@ -702,7 +708,7 @@ public void calculateBoundingBox (BoundingBox bbox) { final int numVertices = getNumVertices(); if (numVertices == 0) throw new GdxRuntimeException("No vertices defined"); - final FloatBuffer verts = vertices.getBuffer(); + final FloatBuffer verts = vertices.getBuffer(false); bbox.inf(); final VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int offset = posAttrib.offset / 4; @@ -772,8 +778,8 @@ public BoundingBox extendBoundingBox (final BoundingBox out, int offset, int cou if (offset < 0 || count < 1 || offset + count > max) throw new GdxRuntimeException("Invalid part specified ( offset=" + offset + ", count=" + count + ", max=" + max + " )"); - final FloatBuffer verts = vertices.getBuffer(); - final ShortBuffer index = indices.getBuffer(); + final FloatBuffer verts = vertices.getBuffer(false); + final ShortBuffer index = indices.getBuffer(false); final VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int posoff = posAttrib.offset / 4; final int vertexSize = vertices.getAttributes().vertexSize / 4; @@ -847,8 +853,8 @@ public float calculateRadiusSquared (final float centerX, final float centerY, f int numIndices = getNumIndices(); if (offset < 0 || count < 1 || offset + count > numIndices) throw new GdxRuntimeException("Not enough indices"); - final FloatBuffer verts = vertices.getBuffer(); - final ShortBuffer index = indices.getBuffer(); + final FloatBuffer verts = vertices.getBuffer(false); + final ShortBuffer index = indices.getBuffer(false); final VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int posoff = posAttrib.offset / 4; final int vertexSize = vertices.getAttributes().vertexSize / 4; @@ -945,9 +951,14 @@ public float calculateRadius (final Vector3 center) { return calculateRadius(center.x, center.y, center.z, 0, getNumIndices(), null); } - /** @return the backing shortbuffer holding the indices. Does not have to be a direct buffer on Android! */ + /** @return the backing shortbuffer holding the indices. Does not have to be a direct buffer on Android! + * @deprecated use {@link #getIndicesBuffer(boolean)} instead */ public ShortBuffer getIndicesBuffer () { - return indices.getBuffer(); + return indices.getBuffer(true); + } + + public ShortBuffer getIndicesBuffer (boolean forWriting) { + return indices.getBuffer(forWriting); } private static void addManagedMesh (Application app, Mesh mesh) { diff --git a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java index 2c3a4131326..0d5ee022fe5 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java +++ b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java @@ -956,8 +956,8 @@ public void flush () { lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); - ((Buffer)mesh.getIndicesBuffer()).position(0); - ((Buffer)mesh.getIndicesBuffer()).limit(count); + ((Buffer) mesh.getIndicesBuffer(true)).position(0); + ((Buffer) mesh.getIndicesBuffer(true)).limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); diff --git a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java index 887dab74a86..7b7cef137f0 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java +++ b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java @@ -171,9 +171,9 @@ public void beginCache () { if (drawing) throw new IllegalStateException("end must be called before beginCache"); if (currentCache != null) throw new IllegalStateException("endCache must be called before begin."); int verticesPerImage = mesh.getNumIndices() > 0 ? 4 : 6; - currentCache = new Cache(caches.size, mesh.getVerticesBuffer().limit()); + currentCache = new Cache(caches.size, mesh.getVerticesBuffer(false).limit()); caches.add(currentCache); - mesh.getVerticesBuffer().compact(); + mesh.getVerticesBuffer(true).compact(); } /** Starts the redefinition of an existing cache, allowing the add and {@link #endCache()} methods to be called. If this is not @@ -184,19 +184,19 @@ public void beginCache (int cacheID) { if (currentCache != null) throw new IllegalStateException("endCache must be called before begin."); if (cacheID == caches.size - 1) { Cache oldCache = caches.removeIndex(cacheID); - ((Buffer)mesh.getVerticesBuffer()).limit(oldCache.offset); + ((Buffer) mesh.getVerticesBuffer(true)).limit(oldCache.offset); beginCache(); return; } currentCache = caches.get(cacheID); - ((Buffer)mesh.getVerticesBuffer()).position(currentCache.offset); + ((Buffer) mesh.getVerticesBuffer(true)).position(currentCache.offset); } /** Ends the definition of a cache, returning the cache ID to be used with {@link #draw(int)}. */ public int endCache () { if (currentCache == null) throw new IllegalStateException("beginCache must be called before endCache."); Cache cache = currentCache; - int cacheCount = mesh.getVerticesBuffer().position() - cache.offset; + int cacheCount = mesh.getVerticesBuffer(false).position() - cache.offset; if (cache.textures == null) { // New cache. cache.maxCount = cacheCount; @@ -206,7 +206,7 @@ public int endCache () { for (int i = 0, n = counts.size; i < n; i++) cache.counts[i] = counts.get(i); - ((Buffer)mesh.getVerticesBuffer()).flip(); + ((Buffer) mesh.getVerticesBuffer(true)).flip(); } else { // Redefine existing cache. if (cacheCount > cache.maxCount) { @@ -225,7 +225,7 @@ public int endCache () { for (int i = 0, n = cache.textureCount; i < n; i++) cache.counts[i] = counts.get(i); - FloatBuffer vertices = mesh.getVerticesBuffer(); + FloatBuffer vertices = mesh.getVerticesBuffer(true); ((Buffer)vertices).position(0); Cache lastCache = caches.get(caches.size - 1); ((Buffer)vertices).limit(lastCache.offset + lastCache.maxCount); @@ -241,7 +241,7 @@ public int endCache () { /** Invalidates all cache IDs and resets the SpriteCache so new caches can be added. */ public void clear () { caches.clear(); - ((Buffer)mesh.getVerticesBuffer()).clear().flip(); + ((Buffer) mesh.getVerticesBuffer(true)).clear().flip(); } /** Adds the specified vertices to the cache. Each vertex should have 5 elements, one for each of the attributes: x, y, color, @@ -259,7 +259,7 @@ public void add (Texture texture, float[] vertices, int offset, int length) { } else counts.incr(lastIndex, count); - mesh.getVerticesBuffer().put(vertices, offset, length); + mesh.getVerticesBuffer(true).put(vertices, offset, length); } /** Adds the specified texture to the cache. */ diff --git a/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java b/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java index 67db485789f..1aba19755f9 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java +++ b/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java @@ -247,9 +247,9 @@ protected void convertMesh (ModelMesh modelMesh) { meshes.add(mesh); disposables.add(mesh); - BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(), modelMesh.vertices.length, 0); + BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(true), modelMesh.vertices.length, 0); int offset = 0; - ((Buffer)mesh.getIndicesBuffer()).clear(); + ((Buffer) mesh.getIndicesBuffer(true)).clear(); for (ModelMeshPart part : modelMesh.parts) { MeshPart meshPart = new MeshPart(); meshPart.id = part.id; @@ -258,12 +258,12 @@ protected void convertMesh (ModelMesh modelMesh) { meshPart.size = hasIndices ? part.indices.length : numVertices; meshPart.mesh = mesh; if (hasIndices) { - mesh.getIndicesBuffer().put(part.indices); + mesh.getIndicesBuffer(true).put(part.indices); } offset += meshPart.size; meshParts.add(meshPart); } - ((Buffer)mesh.getIndicesBuffer()).position(0); + ((Buffer) mesh.getIndicesBuffer(true)).position(0); for (MeshPart part : meshParts) part.update(); } diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexArray.java b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexArray.java index bb833a514f8..287bbc8b2e9 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexArray.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexArray.java @@ -95,17 +95,18 @@ public void updateIndices (int targetOffset, short[] indices, int offset, int co ((Buffer)byteBuffer).position(pos); } - /** - *

- * Returns the underlying ShortBuffer. If you modify the buffer contents they wil be uploaded on the call to {@link #bind()}. - * If you need immediate uploading use {@link #setIndices(short[], int, int)}. - *

- * - * @return the underlying short buffer. */ + /** @deprecated use {@link #getBuffer(boolean)} instead */ + @Override + @Deprecated public ShortBuffer getBuffer () { return buffer; } + @Override + public ShortBuffer getBuffer (boolean forWriting) { + return buffer; + } + /** Binds this IndexArray for rendering with glDrawElements. */ public void bind () { } diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java index 8353d6137f2..d932b50c30e 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java @@ -168,18 +168,20 @@ public void updateIndices (int targetOffset, short[] indices, int offset, int co } } - /** - *

- * Returns the underlying ShortBuffer. If you modify the buffer contents they wil be uploaded on the call to {@link #bind()}. - * If you need immediate uploading use {@link #setIndices(short[], int, int)}. - *

- * - * @return the underlying short buffer. */ + /** @deprecated use {@link #getBuffer(boolean)} instead */ + @Override + @Deprecated public ShortBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public ShortBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Binds this IndexBufferObject for rendering with glDrawElements. */ public void bind () { if (bufferHandle == 0) throw new GdxRuntimeException("No buffer allocated!"); diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObjectSubData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObjectSubData.java index 43fa21fd5aa..4bddfe8d4ae 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObjectSubData.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObjectSubData.java @@ -155,18 +155,20 @@ public void updateIndices (int targetOffset, short[] indices, int offset, int co } } - /** - *

- * Returns the underlying ShortBuffer. If you modify the buffer contents they wil be uploaded on the call to {@link #bind()}. - * If you need immediate uploading use {@link #setIndices(short[], int, int)}. - *

- * - * @return the underlying short buffer. */ + /** @deprecated use {@link #getBuffer(boolean)} instead */ + @Override + @Deprecated public ShortBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public ShortBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Binds this IndexBufferObject for rendering with glDrawElements. */ public void bind () { if (bufferHandle == 0) throw new GdxRuntimeException("IndexBufferObject cannot be used after it has been disposed."); diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexData.java index 2865027a0e0..3f6a45cffb0 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexData.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexData.java @@ -60,13 +60,20 @@ public interface IndexData extends Disposable { /** *

- * Returns the underlying ShortBuffer. If you modify the buffer contents they wil be uploaded on the call to {@link #bind()}. + * Returns the underlying ShortBuffer. If you modify the buffer contents they will be uploaded on the next call to {@link #bind()}. * If you need immediate uploading use {@link #setIndices(short[], int, int)}. *

* - * @return the underlying short buffer. */ + * @return the underlying short buffer. + * @deprecated use {@link #getBuffer(boolean)} instead */ public ShortBuffer getBuffer (); + /** Returns the underlying ShortBuffer for reading or writing. + * @param forWriting when true, the underlying buffer will be uploaded on the next call to {@link #bind()}. If you need + * immediate uploading use {@link #setIndices(short[], int, int)}. + * @return the underlying short buffer. */ + public ShortBuffer getBuffer (boolean forWriting); + /** Binds this IndexBufferObject for rendering with glDrawElements. */ public void bind (); diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java index 67971f24afa..635130e8821 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java @@ -67,12 +67,19 @@ public void dispose () { BufferUtils.disposeUnsafeByteBuffer(byteBuffer); } + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override + @Deprecated public FloatBuffer getBuffer () { return buffer; } @Override + public FloatBuffer getBuffer (boolean forWriting) { + return buffer; + } + + @Override public int getNumVertices () { return buffer.limit() * 4 / attributes.vertexSize; } diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java index cb039cacf01..da4880abdcc 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java @@ -94,12 +94,20 @@ public int getNumMaxVertices () { return byteBuffer.capacity() / attributes.vertexSize; } + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Low level method to reset the buffer and attributes to the specified values. Use with care! * @param data * @param ownsBuffer diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectSubData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectSubData.java index 92e15574b4c..b1bfb89254b 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectSubData.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectSubData.java @@ -100,12 +100,20 @@ public int getNumMaxVertices () { return byteBuffer.capacity() / attributes.vertexSize; } + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + private void bufferChanged () { if (isBound) { Gdx.gl20.glBufferSubData(GL20.GL_ARRAY_BUFFER, 0, byteBuffer.limit(), byteBuffer); diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectWithVAO.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectWithVAO.java index 7a0ec874f48..92b1a80cdeb 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectWithVAO.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectWithVAO.java @@ -104,12 +104,20 @@ public int getNumMaxVertices () { return byteBuffer.capacity() / attributes.vertexSize; } + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + private void bufferChanged () { if (isBound) { Gdx.gl20.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle); diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexData.java index ab8a040b87e..3f709732266 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexData.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexData.java @@ -54,9 +54,17 @@ public interface VertexData extends Disposable { /** Returns the underlying FloatBuffer and marks it as dirty, causing the buffer contents to be uploaded on the next call to * bind. If you need immediate uploading use {@link #setVertices(float[], int, int)}; Any modifications made to the Buffer * *after* the call to bind will not automatically be uploaded. - * @return the underlying FloatBuffer holding the vertex data. */ + * @return the underlying FloatBuffer holding the vertex data. + * @deprecated use {@link #getBuffer(boolean)} instead. */ + @Deprecated public FloatBuffer getBuffer (); + /** Returns the underlying FloatBuffer for reading or writing. + * @param forWriting when true, the underlying buffer will be uploaded on the next call to bind. If you need immediate + * uploading use {@link #setVertices(float[], int, int)}. + * @return the underlying FloatBuffer holding the vertex data. */ + public FloatBuffer getBuffer (boolean forWriting); + /** Binds this VertexData for rendering via glDrawArrays or glDrawElements. */ public void bind (ShaderProgram shader); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOWithVAOPerformanceTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOWithVAOPerformanceTest.java index e032b275833..72142d0e880 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOWithVAOPerformanceTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOWithVAOPerformanceTest.java @@ -346,11 +346,18 @@ public int getNumMaxVertices () { return byteBuffer.capacity() / attributes.vertexSize; } + @Deprecated @Override public FloatBuffer getBuffer () { isDirty = true; return buffer; } + + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } private void bufferChanged () { if (isBound) { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java index 65cedbff1b2..056f697aeed 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java @@ -55,7 +55,7 @@ public void render () { texture.bind(); vbo.bind(shader); indices.bind(); - gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices.getBuffer().position()); + gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices.getBuffer(false).position()); indices.unbind(); vbo.unbind(shader); } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConvexHullDistanceTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConvexHullDistanceTest.java index b657eb4ce25..3d6f2433011 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConvexHullDistanceTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConvexHullDistanceTest.java @@ -97,7 +97,7 @@ public void render () { public static btConvexHullShape createConvexHullShape (final Model model, boolean optimize) { final Mesh mesh = model.meshes.get(0); - final btConvexHullShape shape = new btConvexHullShape(mesh.getVerticesBuffer(), mesh.getNumVertices(), + final btConvexHullShape shape = new btConvexHullShape(mesh.getVerticesBuffer(false), mesh.getNumVertices(), mesh.getVertexSize()); if (!optimize) return shape; // now optimize the shape diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConvexHullTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConvexHullTest.java index f6db0991d24..eec3ea68f7b 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConvexHullTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConvexHullTest.java @@ -54,7 +54,7 @@ public boolean tap (float x, float y, int count, int button) { public static btConvexHullShape createConvexHullShape (final Model model, boolean optimize) { final Mesh mesh = model.meshes.get(0); - final btConvexHullShape shape = new btConvexHullShape(mesh.getVerticesBuffer(), mesh.getNumVertices(), + final btConvexHullShape shape = new btConvexHullShape(mesh.getVerticesBuffer(false), mesh.getNumVertices(), mesh.getVertexSize()); if (!optimize) return shape; // now optimize the shape diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftBodyTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftBodyTest.java index 1d38ef91ff5..1312ca6d6d3 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftBodyTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftBodyTest.java @@ -98,12 +98,12 @@ public void create () { new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); final int vertSize = mesh.getVertexSize() / 4; - ((Buffer)mesh.getVerticesBuffer()).position(0); - ((Buffer)mesh.getVerticesBuffer()).limit(vertCount * vertSize); - ((Buffer)mesh.getIndicesBuffer()).position(0); - ((Buffer)mesh.getIndicesBuffer()).limit(faceCount * 3); - softBody.getVertices(mesh.getVerticesBuffer(), vertCount, mesh.getVertexSize(), 0); - softBody.getIndices(mesh.getIndicesBuffer(), faceCount); + ((Buffer) mesh.getVerticesBuffer(true)).position(0); + ((Buffer) mesh.getVerticesBuffer(true)).limit(vertCount * vertSize); + ((Buffer) mesh.getIndicesBuffer(true)).position(0); + ((Buffer) mesh.getIndicesBuffer(true)).limit(faceCount * 3); + softBody.getVertices(mesh.getVerticesBuffer(true), vertCount, mesh.getVertexSize(), 0); + softBody.getIndices(mesh.getIndicesBuffer(true), faceCount); final float[] verts = new float[vertCount * vertSize]; final int uvOffset = mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4; @@ -150,7 +150,7 @@ public void dispose () { @Override protected void renderWorld () { - softBody.getVertices(mesh.getVerticesBuffer(), softBody.getNodeCount(), mesh.getVertexSize(), 0); + softBody.getVertices(mesh.getVerticesBuffer(true), softBody.getNodeCount(), mesh.getVertexSize(), 0); softBody.getWorldTransform(instance.transform); super.renderWorld(); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftMeshTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftMeshTest.java index 6624865e255..0ea6177c94a 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftMeshTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftMeshTest.java @@ -82,8 +82,8 @@ public void create () { positionOffset = meshPart.mesh.getVertexAttribute(Usage.Position).offset; normalOffset = meshPart.mesh.getVertexAttribute(Usage.Normal).offset; - softBody = new btSoftBody(worldInfo, meshPart.mesh.getVerticesBuffer(), meshPart.mesh.getVertexSize(), positionOffset, - normalOffset, meshPart.mesh.getIndicesBuffer(), meshPart.offset, meshPart.size, indexMap, 0); + softBody = new btSoftBody(worldInfo, meshPart.mesh.getVerticesBuffer(false), meshPart.mesh.getVertexSize(), positionOffset, + normalOffset, meshPart.mesh.getIndicesBuffer(false), meshPart.offset, meshPart.size, indexMap, 0); // Set mass of the first vertex to zero so its unmovable, comment out this line to make it a fully dynamic body. softBody.setMass(0, 0); com.badlogic.gdx.physics.bullet.softbody.btSoftBody.Material pm = softBody.appendMaterial(); @@ -120,8 +120,8 @@ public void dispose () { public void render () { if (world.renderMeshes) { MeshPart meshPart = model.nodes.get(0).parts.get(0).meshPart; - softBody.getVertices(meshPart.mesh.getVerticesBuffer(), meshPart.mesh.getVertexSize(), positionOffset, normalOffset, - meshPart.mesh.getIndicesBuffer(), meshPart.offset, meshPart.size, indexMap, 0); + softBody.getVertices(meshPart.mesh.getVerticesBuffer(true), meshPart.mesh.getVertexSize(), positionOffset, normalOffset, + meshPart.mesh.getIndicesBuffer(false), meshPart.offset, meshPart.size, indexMap, 0); softBody.getWorldTransform(entity.transform); } super.render(); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/TriangleRaycastTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/TriangleRaycastTest.java index 939ef602983..bf3e456f293 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/TriangleRaycastTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/TriangleRaycastTest.java @@ -172,8 +172,8 @@ public boolean tap (float screenX, float screenY, int count, int button) { // Get the position coordinates of the vertices belonging to intersected triangle. Mesh mesh = model.meshParts.get(currentPartId).mesh; - FloatBuffer verticesBuffer = mesh.getVerticesBuffer(); - ShortBuffer indicesBuffer = mesh.getIndicesBuffer(); + FloatBuffer verticesBuffer = mesh.getVerticesBuffer(false); + ShortBuffer indicesBuffer = mesh.getIndicesBuffer(false); int posOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4; int vertexSize = mesh.getVertexSize() / 4; @@ -181,7 +181,7 @@ public boolean tap (float screenX, float screenY, int count, int button) { // Store the three vertices belonging to the selected triangle. for (int i = 0; i < 3; i++) { - int currentVertexIndex = indicesBuffer.get(currentTriangleFirstVertexIndex + i); + int currentVertexIndex = indicesBuffer.get(currentTriangleFirstVertexIndex + i) & 0xFFFF; int j = currentVertexIndex * vertexSize + posOffset; float x = verticesBuffer.get(j++); float y = verticesBuffer.get(j++); From f04f4b6022a381f8c4acdcc66f731e8acb2c7559 Mon Sep 17 00:00:00 2001 From: Germain AUBERT Date: Tue, 23 Feb 2021 22:12:38 +0100 Subject: [PATCH 2/5] simplify code --- gdx/src/com/badlogic/gdx/graphics/Mesh.java | 18 ++++++++++-------- .../badlogic/gdx/graphics/g2d/SpriteBatch.java | 5 +++-- .../badlogic/gdx/graphics/g2d/SpriteCache.java | 10 ++++++---- .../com/badlogic/gdx/graphics/g3d/Model.java | 8 +++++--- .../gdx/tests/bullet/SoftBodyTest.java | 16 ++++++++++------ 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/gdx/src/com/badlogic/gdx/graphics/Mesh.java b/gdx/src/com/badlogic/gdx/graphics/Mesh.java index b51d8ab0c33..d6a99edb417 100644 --- a/gdx/src/com/badlogic/gdx/graphics/Mesh.java +++ b/gdx/src/com/badlogic/gdx/graphics/Mesh.java @@ -389,10 +389,11 @@ public float[] getVertices (int srcOffset, int count, float[] vertices, int dest throw new IndexOutOfBoundsException(); if ((vertices.length - destOffset) < count) throw new IllegalArgumentException( "not enough room in vertices array, has " + vertices.length + " floats, needs " + count); - int pos = getVerticesBuffer(false).position(); - ((Buffer) getVerticesBuffer(false)).position(srcOffset); - getVerticesBuffer(false).get(vertices, destOffset, count); - ((Buffer) getVerticesBuffer(false)).position(pos); + FloatBuffer verticesBuffer = getVerticesBuffer(false); + int pos = verticesBuffer.position(); + ((Buffer)verticesBuffer).position(srcOffset); + verticesBuffer.get(vertices, destOffset, count); + ((Buffer)verticesBuffer).position(pos); return vertices; } @@ -454,10 +455,11 @@ public void getIndices (int srcOffset, int count, short[] indices, int destOffse "Invalid range specified, offset: " + srcOffset + ", count: " + count + ", max: " + max); if ((indices.length - destOffset) < count) throw new IllegalArgumentException( "not enough room in indices array, has " + indices.length + " shorts, needs " + count); - int pos = getIndicesBuffer(false).position(); - ((Buffer) getIndicesBuffer(false)).position(srcOffset); - getIndicesBuffer(false).get(indices, destOffset, count); - ((Buffer) getIndicesBuffer(false)).position(pos); + ShortBuffer indicesBuffer = getIndicesBuffer(false); + int pos = indicesBuffer.position(); + ((Buffer)indicesBuffer).position(srcOffset); + indicesBuffer.get(indices, destOffset, count); + ((Buffer)indicesBuffer).position(pos); } /** @return the number of defined indices */ diff --git a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java index 0d5ee022fe5..d9d88a53703 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java +++ b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java @@ -956,8 +956,9 @@ public void flush () { lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); - ((Buffer) mesh.getIndicesBuffer(true)).position(0); - ((Buffer) mesh.getIndicesBuffer(true)).limit(count); + Buffer indicesBuffer = (Buffer)mesh.getIndicesBuffer(true); + indicesBuffer.position(0); + indicesBuffer.limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); diff --git a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java index 7b7cef137f0..3833166c142 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java +++ b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java @@ -171,9 +171,10 @@ public void beginCache () { if (drawing) throw new IllegalStateException("end must be called before beginCache"); if (currentCache != null) throw new IllegalStateException("endCache must be called before begin."); int verticesPerImage = mesh.getNumIndices() > 0 ? 4 : 6; - currentCache = new Cache(caches.size, mesh.getVerticesBuffer(false).limit()); + FloatBuffer verticesBuffer = mesh.getVerticesBuffer(true); + currentCache = new Cache(caches.size, verticesBuffer.limit()); caches.add(currentCache); - mesh.getVerticesBuffer(true).compact(); + verticesBuffer.compact(); } /** Starts the redefinition of an existing cache, allowing the add and {@link #endCache()} methods to be called. If this is not @@ -182,14 +183,15 @@ public void beginCache () { public void beginCache (int cacheID) { if (drawing) throw new IllegalStateException("end must be called before beginCache"); if (currentCache != null) throw new IllegalStateException("endCache must be called before begin."); + Buffer verticesBuffer = (Buffer)mesh.getVerticesBuffer(true); if (cacheID == caches.size - 1) { Cache oldCache = caches.removeIndex(cacheID); - ((Buffer) mesh.getVerticesBuffer(true)).limit(oldCache.offset); + verticesBuffer.limit(oldCache.offset); beginCache(); return; } currentCache = caches.get(cacheID); - ((Buffer) mesh.getVerticesBuffer(true)).position(currentCache.offset); + verticesBuffer.position(currentCache.offset); } /** Ends the definition of a cache, returning the cache ID to be used with {@link #draw(int)}. */ diff --git a/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java b/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java index 1aba19755f9..cee9b17275a 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java +++ b/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java @@ -56,6 +56,7 @@ import com.badlogic.gdx.utils.ObjectMap; import java.nio.Buffer; +import java.nio.ShortBuffer; /** A model represents a 3D assets. It stores a hierarchy of nodes. A node has a transform and optionally a graphical part in form * of a {@link MeshPart} and {@link Material}. Mesh parts reference subsets of vertices in one of the meshes of the model. @@ -249,7 +250,8 @@ protected void convertMesh (ModelMesh modelMesh) { BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(true), modelMesh.vertices.length, 0); int offset = 0; - ((Buffer) mesh.getIndicesBuffer(true)).clear(); + ShortBuffer indicesBuffer = mesh.getIndicesBuffer(true); + ((Buffer)indicesBuffer).clear(); for (ModelMeshPart part : modelMesh.parts) { MeshPart meshPart = new MeshPart(); meshPart.id = part.id; @@ -258,12 +260,12 @@ protected void convertMesh (ModelMesh modelMesh) { meshPart.size = hasIndices ? part.indices.length : numVertices; meshPart.mesh = mesh; if (hasIndices) { - mesh.getIndicesBuffer(true).put(part.indices); + indicesBuffer.put(part.indices); } offset += meshPart.size; meshParts.add(meshPart); } - ((Buffer) mesh.getIndicesBuffer(true)).position(0); + ((Buffer)indicesBuffer).position(0); for (MeshPart part : meshParts) part.update(); } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftBodyTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftBodyTest.java index 1312ca6d6d3..d3054813188 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftBodyTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/SoftBodyTest.java @@ -46,6 +46,8 @@ import com.badlogic.gdx.physics.bullet.softbody.btSoftRigidDynamicsWorld; import java.nio.Buffer; +import java.nio.FloatBuffer; +import java.nio.ShortBuffer; /** @author xoppa */ public class SoftBodyTest extends BaseBulletTest { @@ -98,12 +100,14 @@ public void create () { new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); final int vertSize = mesh.getVertexSize() / 4; - ((Buffer) mesh.getVerticesBuffer(true)).position(0); - ((Buffer) mesh.getVerticesBuffer(true)).limit(vertCount * vertSize); - ((Buffer) mesh.getIndicesBuffer(true)).position(0); - ((Buffer) mesh.getIndicesBuffer(true)).limit(faceCount * 3); - softBody.getVertices(mesh.getVerticesBuffer(true), vertCount, mesh.getVertexSize(), 0); - softBody.getIndices(mesh.getIndicesBuffer(true), faceCount); + FloatBuffer verticesBuffer = mesh.getVerticesBuffer(true); + ((Buffer)verticesBuffer).position(0); + ((Buffer)verticesBuffer).limit(vertCount * vertSize); + ShortBuffer indicesBuffer = mesh.getIndicesBuffer(true); + ((Buffer)indicesBuffer).position(0); + ((Buffer)indicesBuffer).limit(faceCount * 3); + softBody.getVertices(verticesBuffer, vertCount, mesh.getVertexSize(), 0); + softBody.getIndices(indicesBuffer, faceCount); final float[] verts = new float[vertCount * vertSize]; final int uvOffset = mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4; From b6d788be694d082fd715b92c0d18530c827e209c Mon Sep 17 00:00:00 2001 From: Germain AUBERT Date: Tue, 23 Feb 2021 22:48:16 +0100 Subject: [PATCH 3/5] apply to InstanceData --- .../gdx/graphics/glutils/InstanceBufferObject.java | 8 ++++++++ .../gdx/graphics/glutils/InstanceBufferObject.java | 8 ++++++++ .../graphics/glutils/InstanceBufferObjectSubData.java | 8 ++++++++ .../badlogic/gdx/graphics/glutils/InstanceData.java | 10 +++++++++- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/InstanceBufferObject.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/InstanceBufferObject.java index 54cd3acda0b..382baaff780 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/InstanceBufferObject.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/InstanceBufferObject.java @@ -73,12 +73,20 @@ public int getNumMaxInstances () { return byteBuffer.capacity() / attributes.vertexSize; } + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Low level method to reset the buffer and attributes to the specified values. Use with care! * * @param data diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceBufferObject.java b/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceBufferObject.java index ddb7ee1b1d7..750c546e32a 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceBufferObject.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceBufferObject.java @@ -73,12 +73,20 @@ public int getNumMaxInstances () { return byteBuffer.capacity() / attributes.vertexSize; } + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Low level method to reset the buffer and attributes to the specified values. Use with care! * * @param data diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceBufferObjectSubData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceBufferObjectSubData.java index 28fb31112d7..29f97cdfc6c 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceBufferObjectSubData.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceBufferObjectSubData.java @@ -99,12 +99,20 @@ public int getNumMaxInstances () { return byteBuffer.capacity() / attributes.vertexSize; } + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + private void bufferChanged () { if (isBound) { Gdx.gl20.glBufferData(GL20.GL_ARRAY_BUFFER, byteBuffer.limit(), null, usage); diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceData.java index 42f3ad97c99..8ef225b42f4 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceData.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/InstanceData.java @@ -75,9 +75,17 @@ public interface InstanceData extends Disposable { * bind. If you need immediate uploading use {@link #setInstanceData(float[], int, int)}; Any modifications made to the Buffer * *after* the call to bind will not automatically be uploaded. * - * @return the underlying FloatBuffer holding the vertex data. */ + * @return the underlying FloatBuffer holding the vertex data. + * @deprecated use {@link #getBuffer(boolean)} instead */ + @Deprecated public FloatBuffer getBuffer (); + /** Returns the underlying FloatBuffer for reading or writing. + * @param forWriting when true, the underlying buffer will be uploaded on the next call to bind. If you need immediate + * uploading use {@link #setInstanceData(float[], int, int)}. + * @return the underlying FloatBuffer holding the vertex data. */ + public FloatBuffer getBuffer (boolean forWriting); + /** Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced. */ public void bind (ShaderProgram shader); From 433466a3e68f1d847c72b566d0027400ae461e6c Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 2 Dec 2021 16:11:41 +0000 Subject: [PATCH 4/5] Apply formatter --- .../graphics/glutils/IndexBufferObject.java | 12 +++--- .../graphics/glutils/VertexBufferObject.java | 16 +++---- .../bullet/collision/btIndexedMesh.java | 3 +- gdx/src/com/badlogic/gdx/graphics/Mesh.java | 42 +++++++++---------- .../gdx/graphics/g2d/SpriteCache.java | 16 +++---- .../com/badlogic/gdx/graphics/g3d/Model.java | 8 ++-- .../gdx/graphics/glutils/IndexArray.java | 10 ++--- .../graphics/glutils/IndexBufferObject.java | 12 +++--- .../glutils/IndexBufferObjectSubData.java | 12 +++--- .../gdx/graphics/glutils/IndexData.java | 4 +- .../gdx/graphics/glutils/VertexArray.java | 14 +++---- .../graphics/glutils/VertexBufferObject.java | 16 +++---- .../glutils/VertexBufferObjectSubData.java | 16 +++---- .../gdx/tests/VBOWithVAOPerformanceTest.java | 2 +- .../tests/VertexBufferObjectShaderTest.java | 2 +- 15 files changed, 93 insertions(+), 92 deletions(-) diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java index e879153329b..23f7f11ca3b 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java @@ -144,12 +144,12 @@ public ShortBuffer getBuffer () { return buffer; } - @Override - public ShortBuffer getBuffer (boolean forWriting) { - isDirty |= forWriting; - return buffer; - } - + @Override + public ShortBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Binds this IndexBufferObject for rendering with glDrawElements. */ public void bind () { if (bufferHandle == 0) throw new GdxRuntimeException("No buffer allocated!"); diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java index fddb8ff63f3..33b1fdaa072 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java @@ -96,20 +96,20 @@ public int getNumMaxVertices () { return buffer.capacity() / (attributes.vertexSize / 4); } - /** @deprecated use {@link #getBuffer(boolean)} instead */ + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override - @Deprecated + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } - @Override - public FloatBuffer getBuffer (boolean forWriting) { - isDirty |= forWriting; - return buffer; - } - + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + private void bufferChanged () { if (isBound) { Gdx.gl20.glBufferData(GL20.GL_ARRAY_BUFFER, buffer.limit(), buffer, usage); diff --git a/extensions/gdx-bullet/jni/swig-src/collision/com/badlogic/gdx/physics/bullet/collision/btIndexedMesh.java b/extensions/gdx-bullet/jni/swig-src/collision/com/badlogic/gdx/physics/bullet/collision/btIndexedMesh.java index 78d02d74886..6554d3619ab 100644 --- a/extensions/gdx-bullet/jni/swig-src/collision/com/badlogic/gdx/physics/bullet/collision/btIndexedMesh.java +++ b/extensions/gdx-bullet/jni/swig-src/collision/com/badlogic/gdx/physics/bullet/collision/btIndexedMesh.java @@ -172,7 +172,8 @@ public void set (final Object tag, final Mesh mesh, int offset, int count) { if (posAttr == null) throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh doesn't have a position attribute"); - set(tag, mesh.getVerticesBuffer(false), mesh.getVertexSize(), mesh.getNumVertices(), posAttr.offset, mesh.getIndicesBuffer(false), offset, count); + set(tag, mesh.getVerticesBuffer(false), mesh.getVertexSize(), mesh.getNumVertices(), posAttr.offset, + mesh.getIndicesBuffer(false), offset, count); } /** Convenience method to set this btIndexedMesh to the specified vertex and index data. The specified data must be indexed and diff --git a/gdx/src/com/badlogic/gdx/graphics/Mesh.java b/gdx/src/com/badlogic/gdx/graphics/Mesh.java index d6a99edb417..163cdb6796a 100644 --- a/gdx/src/com/badlogic/gdx/graphics/Mesh.java +++ b/gdx/src/com/badlogic/gdx/graphics/Mesh.java @@ -619,7 +619,7 @@ public void render (ShaderProgram shader, int primitiveType, int offset, int cou if (isVertexArray) { if (indices.getNumIndices() > 0) { - ShortBuffer buffer = indices.getBuffer(false); + ShortBuffer buffer = indices.getBuffer(false); int oldPosition = buffer.position(); int oldLimit = buffer.limit(); ((Buffer)buffer).position(offset); @@ -681,15 +681,15 @@ public VertexAttributes getVertexAttributes () { return vertices.getAttributes(); } - /** @return the backing FloatBuffer holding the vertices. Does not have to be a direct buffer on Android! - * @deprecated use {@link #getVerticesBuffer(boolean)} instead */ - @Deprecated + /** @return the backing FloatBuffer holding the vertices. Does not have to be a direct buffer on Android! + * @deprecated use {@link #getVerticesBuffer(boolean)} instead */ + @Deprecated public FloatBuffer getVerticesBuffer () { - return vertices.getBuffer(true); - } - - public FloatBuffer getVerticesBuffer (boolean forWriting) { - return vertices.getBuffer(forWriting); + return vertices.getBuffer(true); + } + + public FloatBuffer getVerticesBuffer (boolean forWriting) { + return vertices.getBuffer(forWriting); } /** Calculates the {@link BoundingBox} of the vertices contained in this mesh. In case no vertices are defined yet a @@ -710,7 +710,7 @@ public void calculateBoundingBox (BoundingBox bbox) { final int numVertices = getNumVertices(); if (numVertices == 0) throw new GdxRuntimeException("No vertices defined"); - final FloatBuffer verts = vertices.getBuffer(false); + final FloatBuffer verts = vertices.getBuffer(false); bbox.inf(); final VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int offset = posAttrib.offset / 4; @@ -780,8 +780,8 @@ public BoundingBox extendBoundingBox (final BoundingBox out, int offset, int cou if (offset < 0 || count < 1 || offset + count > max) throw new GdxRuntimeException("Invalid part specified ( offset=" + offset + ", count=" + count + ", max=" + max + " )"); - final FloatBuffer verts = vertices.getBuffer(false); - final ShortBuffer index = indices.getBuffer(false); + final FloatBuffer verts = vertices.getBuffer(false); + final ShortBuffer index = indices.getBuffer(false); final VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int posoff = posAttrib.offset / 4; final int vertexSize = vertices.getAttributes().vertexSize / 4; @@ -855,8 +855,8 @@ public float calculateRadiusSquared (final float centerX, final float centerY, f int numIndices = getNumIndices(); if (offset < 0 || count < 1 || offset + count > numIndices) throw new GdxRuntimeException("Not enough indices"); - final FloatBuffer verts = vertices.getBuffer(false); - final ShortBuffer index = indices.getBuffer(false); + final FloatBuffer verts = vertices.getBuffer(false); + final ShortBuffer index = indices.getBuffer(false); final VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int posoff = posAttrib.offset / 4; final int vertexSize = vertices.getAttributes().vertexSize / 4; @@ -953,14 +953,14 @@ public float calculateRadius (final Vector3 center) { return calculateRadius(center.x, center.y, center.z, 0, getNumIndices(), null); } - /** @return the backing shortbuffer holding the indices. Does not have to be a direct buffer on Android! - * @deprecated use {@link #getIndicesBuffer(boolean)} instead */ + /** @return the backing shortbuffer holding the indices. Does not have to be a direct buffer on Android! + * @deprecated use {@link #getIndicesBuffer(boolean)} instead */ public ShortBuffer getIndicesBuffer () { - return indices.getBuffer(true); - } - - public ShortBuffer getIndicesBuffer (boolean forWriting) { - return indices.getBuffer(forWriting); + return indices.getBuffer(true); + } + + public ShortBuffer getIndicesBuffer (boolean forWriting) { + return indices.getBuffer(forWriting); } private static void addManagedMesh (Application app, Mesh mesh) { diff --git a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java index 3833166c142..b8efe50984b 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java +++ b/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteCache.java @@ -183,22 +183,22 @@ public void beginCache () { public void beginCache (int cacheID) { if (drawing) throw new IllegalStateException("end must be called before beginCache"); if (currentCache != null) throw new IllegalStateException("endCache must be called before begin."); - Buffer verticesBuffer = (Buffer)mesh.getVerticesBuffer(true); + Buffer verticesBuffer = (Buffer)mesh.getVerticesBuffer(true); if (cacheID == caches.size - 1) { Cache oldCache = caches.removeIndex(cacheID); - verticesBuffer.limit(oldCache.offset); + verticesBuffer.limit(oldCache.offset); beginCache(); return; } currentCache = caches.get(cacheID); - verticesBuffer.position(currentCache.offset); + verticesBuffer.position(currentCache.offset); } /** Ends the definition of a cache, returning the cache ID to be used with {@link #draw(int)}. */ public int endCache () { if (currentCache == null) throw new IllegalStateException("beginCache must be called before endCache."); Cache cache = currentCache; - int cacheCount = mesh.getVerticesBuffer(false).position() - cache.offset; + int cacheCount = mesh.getVerticesBuffer(false).position() - cache.offset; if (cache.textures == null) { // New cache. cache.maxCount = cacheCount; @@ -208,7 +208,7 @@ public int endCache () { for (int i = 0, n = counts.size; i < n; i++) cache.counts[i] = counts.get(i); - ((Buffer) mesh.getVerticesBuffer(true)).flip(); + ((Buffer)mesh.getVerticesBuffer(true)).flip(); } else { // Redefine existing cache. if (cacheCount > cache.maxCount) { @@ -227,7 +227,7 @@ public int endCache () { for (int i = 0, n = cache.textureCount; i < n; i++) cache.counts[i] = counts.get(i); - FloatBuffer vertices = mesh.getVerticesBuffer(true); + FloatBuffer vertices = mesh.getVerticesBuffer(true); ((Buffer)vertices).position(0); Cache lastCache = caches.get(caches.size - 1); ((Buffer)vertices).limit(lastCache.offset + lastCache.maxCount); @@ -243,7 +243,7 @@ public int endCache () { /** Invalidates all cache IDs and resets the SpriteCache so new caches can be added. */ public void clear () { caches.clear(); - ((Buffer) mesh.getVerticesBuffer(true)).clear().flip(); + ((Buffer)mesh.getVerticesBuffer(true)).clear().flip(); } /** Adds the specified vertices to the cache. Each vertex should have 5 elements, one for each of the attributes: x, y, color, @@ -261,7 +261,7 @@ public void add (Texture texture, float[] vertices, int offset, int length) { } else counts.incr(lastIndex, count); - mesh.getVerticesBuffer(true).put(vertices, offset, length); + mesh.getVerticesBuffer(true).put(vertices, offset, length); } /** Adds the specified texture to the cache. */ diff --git a/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java b/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java index cee9b17275a..962faca85b0 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java +++ b/gdx/src/com/badlogic/gdx/graphics/g3d/Model.java @@ -56,7 +56,7 @@ import com.badlogic.gdx.utils.ObjectMap; import java.nio.Buffer; -import java.nio.ShortBuffer; +import java.nio.ShortBuffer; /** A model represents a 3D assets. It stores a hierarchy of nodes. A node has a transform and optionally a graphical part in form * of a {@link MeshPart} and {@link Material}. Mesh parts reference subsets of vertices in one of the meshes of the model. @@ -248,7 +248,7 @@ protected void convertMesh (ModelMesh modelMesh) { meshes.add(mesh); disposables.add(mesh); - BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(true), modelMesh.vertices.length, 0); + BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(true), modelMesh.vertices.length, 0); int offset = 0; ShortBuffer indicesBuffer = mesh.getIndicesBuffer(true); ((Buffer)indicesBuffer).clear(); @@ -260,12 +260,12 @@ protected void convertMesh (ModelMesh modelMesh) { meshPart.size = hasIndices ? part.indices.length : numVertices; meshPart.mesh = mesh; if (hasIndices) { - indicesBuffer.put(part.indices); + indicesBuffer.put(part.indices); } offset += meshPart.size; meshParts.add(meshPart); } - ((Buffer)indicesBuffer).position(0); + ((Buffer)indicesBuffer).position(0); for (MeshPart part : meshParts) part.update(); } diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexArray.java b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexArray.java index 287bbc8b2e9..4aa1b839714 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexArray.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexArray.java @@ -102,11 +102,11 @@ public ShortBuffer getBuffer () { return buffer; } - @Override - public ShortBuffer getBuffer (boolean forWriting) { - return buffer; - } - + @Override + public ShortBuffer getBuffer (boolean forWriting) { + return buffer; + } + /** Binds this IndexArray for rendering with glDrawElements. */ public void bind () { } diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java index d932b50c30e..5a1c4c3e866 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java @@ -176,12 +176,12 @@ public ShortBuffer getBuffer () { return buffer; } - @Override - public ShortBuffer getBuffer (boolean forWriting) { - isDirty |= forWriting; - return buffer; - } - + @Override + public ShortBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Binds this IndexBufferObject for rendering with glDrawElements. */ public void bind () { if (bufferHandle == 0) throw new GdxRuntimeException("No buffer allocated!"); diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObjectSubData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObjectSubData.java index 4bddfe8d4ae..68bbc1cc8eb 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObjectSubData.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObjectSubData.java @@ -163,12 +163,12 @@ public ShortBuffer getBuffer () { return buffer; } - @Override - public ShortBuffer getBuffer (boolean forWriting) { - isDirty |= forWriting; - return buffer; - } - + @Override + public ShortBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Binds this IndexBufferObject for rendering with glDrawElements. */ public void bind () { if (bufferHandle == 0) throw new GdxRuntimeException("IndexBufferObject cannot be used after it has been disposed."); diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexData.java index 3f6a45cffb0..ede9b0bf64c 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/IndexData.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/IndexData.java @@ -60,8 +60,8 @@ public interface IndexData extends Disposable { /** *

- * Returns the underlying ShortBuffer. If you modify the buffer contents they will be uploaded on the next call to {@link #bind()}. - * If you need immediate uploading use {@link #setIndices(short[], int, int)}. + * Returns the underlying ShortBuffer. If you modify the buffer contents they will be uploaded on the next call to + * {@link #bind()}. If you need immediate uploading use {@link #setIndices(short[], int, int)}. *

* * @return the underlying short buffer. diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java index 635130e8821..44725b6d107 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java @@ -67,19 +67,19 @@ public void dispose () { BufferUtils.disposeUnsafeByteBuffer(byteBuffer); } - /** @deprecated use {@link #getBuffer(boolean)} instead */ + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override - @Deprecated + @Deprecated public FloatBuffer getBuffer () { return buffer; } @Override - public FloatBuffer getBuffer (boolean forWriting) { - return buffer; - } - - @Override + public FloatBuffer getBuffer (boolean forWriting) { + return buffer; + } + + @Override public int getNumVertices () { return buffer.limit() * 4 / attributes.vertexSize; } diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java index da4880abdcc..30ba6cba83f 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java @@ -94,20 +94,20 @@ public int getNumMaxVertices () { return byteBuffer.capacity() / attributes.vertexSize; } - /** @deprecated use {@link #getBuffer(boolean)} instead */ + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override - @Deprecated + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } - @Override - public FloatBuffer getBuffer (boolean forWriting) { - isDirty |= forWriting; - return buffer; - } - + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + /** Low level method to reset the buffer and attributes to the specified values. Use with care! * @param data * @param ownsBuffer diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectSubData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectSubData.java index b1bfb89254b..44ab1755158 100644 --- a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectSubData.java +++ b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectSubData.java @@ -100,20 +100,20 @@ public int getNumMaxVertices () { return byteBuffer.capacity() / attributes.vertexSize; } - /** @deprecated use {@link #getBuffer(boolean)} instead */ + /** @deprecated use {@link #getBuffer(boolean)} instead */ @Override - @Deprecated + @Deprecated public FloatBuffer getBuffer () { isDirty = true; return buffer; } - @Override - public FloatBuffer getBuffer (boolean forWriting) { - isDirty |= forWriting; - return buffer; - } - + @Override + public FloatBuffer getBuffer (boolean forWriting) { + isDirty |= forWriting; + return buffer; + } + private void bufferChanged () { if (isBound) { Gdx.gl20.glBufferSubData(GL20.GL_ARRAY_BUFFER, 0, byteBuffer.limit(), byteBuffer); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOWithVAOPerformanceTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOWithVAOPerformanceTest.java index 72142d0e880..585aae0f6d6 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOWithVAOPerformanceTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOWithVAOPerformanceTest.java @@ -352,7 +352,7 @@ public FloatBuffer getBuffer () { isDirty = true; return buffer; } - + @Override public FloatBuffer getBuffer (boolean forWriting) { isDirty |= forWriting; diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java index 056f697aeed..f56ddeffb4d 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java @@ -55,7 +55,7 @@ public void render () { texture.bind(); vbo.bind(shader); indices.bind(); - gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices.getBuffer(false).position()); + gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices.getBuffer(false).position()); indices.unbind(); vbo.unbind(shader); } From 300d5131966c37ad13db938e2622ddaca5f51c88 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 15 Nov 2022 19:37:01 +0000 Subject: [PATCH 5/5] Apply formatter --- .../gdx/backends/android/AndroidApplicationConfiguration.java | 2 +- .../src/com/badlogic/gdx/backends/android/GdxNativeLoader.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplicationConfiguration.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplicationConfiguration.java index c511bd4d6e1..836d8d6d654 100644 --- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplicationConfiguration.java +++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplicationConfiguration.java @@ -103,7 +103,7 @@ public class AndroidApplicationConfiguration { /** The loader used to load native libraries. Override this to use a different loading strategy. */ public GdxNativeLoader nativeLoader = new GdxNativeLoader() { @Override - public void load() { + public void load () { GdxNativesLoader.load(); } }; diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/GdxNativeLoader.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/GdxNativeLoader.java index e65afd4d002..5ba0d6976a7 100644 --- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/GdxNativeLoader.java +++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/GdxNativeLoader.java @@ -20,5 +20,5 @@ public interface GdxNativeLoader { /** Load GDX native libraries. */ - void load(); + void load (); }