diff --git a/jme3-core/src/main/java/com/jme3/shader/bufferobject/BufferObject.java b/jme3-core/src/main/java/com/jme3/shader/bufferobject/BufferObject.java index f83c68c1aa..f40cbfd26d 100644 --- a/jme3-core/src/main/java/com/jme3/shader/bufferobject/BufferObject.java +++ b/jme3-core/src/main/java/com/jme3/shader/bufferobject/BufferObject.java @@ -269,7 +269,9 @@ public void markAllRegionsDirty() { @Override public void resetObject() { - this.id = -1; + this.id = INVALID_ID; + // A replacement GPU allocation needs all retained CPU data. + setUpdateNeeded(); } @Override diff --git a/jme3-core/src/test/java/com/jme3/shader/bufferobject/BufferObjectResetTest.java b/jme3-core/src/test/java/com/jme3/shader/bufferobject/BufferObjectResetTest.java new file mode 100644 index 0000000000..1dbff34116 --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/shader/bufferobject/BufferObjectResetTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009-2026 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.shader.bufferobject; + +import java.util.Arrays; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class BufferObjectResetTest { + @Test + void bufferObjectResetMarksItsDataAndRegionsForUpload() { + BufferObject buffer = new BufferObject(); + buffer.setId(74); + buffer.setRegions(Arrays.asList(new BufferRegion(0, 3), new BufferRegion(4, 7))); + buffer.getRegion(0).clearDirty(); + buffer.getRegion(1).clearDirty(); + buffer.clearUpdateNeeded(); + + buffer.resetObject(); + + assertTrue(buffer.isUpdateNeeded()); + assertTrue(buffer.getRegion(0).isDirty()); + assertTrue(buffer.getRegion(1).isDirty()); + } + +}