Skip to content

Commit fa6083f

Browse files
authored
solution for issue #2250 (exceptions from Image.setMultiSamples(1)) (#2251)
1 parent ff7374b commit fa6083f

2 files changed

Lines changed: 90 additions & 6 deletions

File tree

jme3-core/src/main/java/com/jme3/texture/Image.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2023 jMonkeyEngine
2+
* Copyright (c) 2009-2024 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -942,14 +942,19 @@ public int getMultiSamples() {
942942
* into a multisample texture (on OpenGL3.1 and higher).
943943
*/
944944
public void setMultiSamples(int multiSamples) {
945-
if (multiSamples <= 0)
945+
if (multiSamples <= 0) {
946946
throw new IllegalArgumentException("multiSamples must be > 0");
947+
}
947948

948-
if (getData(0) != null)
949-
throw new IllegalArgumentException("Cannot upload data as multisample texture");
949+
if (multiSamples > 1) {
950+
if (getData(0) != null) {
951+
throw new IllegalArgumentException("Cannot upload data as multisample texture");
952+
}
950953

951-
if (hasMipmaps())
952-
throw new IllegalArgumentException("Multisample textures do not support mipmaps");
954+
if (hasMipmaps()) {
955+
throw new IllegalArgumentException("Multisample textures do not support mipmaps");
956+
}
957+
}
953958

954959
this.multiSamples = multiSamples;
955960
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2024 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.jme3.texture;
33+
34+
import com.jme3.texture.image.ColorSpace;
35+
import com.jme3.util.BufferUtils;
36+
import java.nio.ByteBuffer;
37+
import java.util.ArrayList;
38+
import org.junit.Test;
39+
40+
/**
41+
* Verify that setMultiSamples(1) can be applied to any Image. This was issue
42+
* #2250 at GitHub.
43+
*
44+
* @author Stephen Gold
45+
*/
46+
public class TestIssue2250 {
47+
48+
/**
49+
* Test setMultiSamples() on an Image with a data buffer.
50+
*/
51+
@Test
52+
public void testIssue2250WithData() {
53+
int width = 8;
54+
int height = 8;
55+
int numBytes = 4 * width * height;
56+
ByteBuffer data = BufferUtils.createByteBuffer(numBytes);
57+
Image image1 = new Image(
58+
Image.Format.RGBA8, width, height, data, ColorSpace.Linear);
59+
60+
image1.setMultiSamples(1);
61+
}
62+
63+
/**
64+
* Test setMultiSamples() on an Image with mip maps.
65+
*/
66+
@Test
67+
public void testIssue2250WithMips() {
68+
int width = 8;
69+
int height = 8;
70+
int depth = 1;
71+
int[] mipMapSizes = {256, 64, 16, 4};
72+
73+
ArrayList<ByteBuffer> data = new ArrayList<>();
74+
Image image2 = new Image(Image.Format.RGBA8, width, height, depth, data,
75+
mipMapSizes, ColorSpace.Linear);
76+
77+
image2.setMultiSamples(1);
78+
}
79+
}

0 commit comments

Comments
 (0)