|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright (c) 2009-2019 jMonkeyEngine
|
|
|
+ * Copyright (c) 2009-2020 jMonkeyEngine
|
|
|
* All rights reserved.
|
|
|
*
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
@@ -92,7 +92,7 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
|
|
|
private int textureAtlasId = 1;
|
|
|
private Batch currentBatch;
|
|
|
private Matrix4f tempMat = new Matrix4f();
|
|
|
- private ByteBuffer initialData;
|
|
|
+ private ByteBuffer initialData = null;
|
|
|
|
|
|
// this is only used for debugging purpose and will make the removed textures filled with a color
|
|
|
// please note: the old way to init this via a system property has been
|
|
@@ -186,16 +186,19 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
|
|
|
@Override
|
|
|
public int createTextureAtlas(final int width, final int height) {
|
|
|
try {
|
|
|
+ // we initialize a buffer here that will be used as base for all texture atlas images
|
|
|
+ if (initialData == null) {
|
|
|
+ initialData = BufferUtils.createByteBuffer(width * height * 4);
|
|
|
+ for (int i = 0; i < width * height; i++) {
|
|
|
+ initialData.put((byte) 0x00);
|
|
|
+ initialData.put((byte) 0x00);
|
|
|
+ initialData.put((byte) 0x00);
|
|
|
+ initialData.put((byte) 0xff);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
int atlasId = addTexture(createAtlasTextureInternal(width, height));
|
|
|
|
|
|
- // we just initialize a second buffer here that will replace the texture atlas image
|
|
|
- initialData = BufferUtils.createByteBuffer(width * height * 4);
|
|
|
- for (int i = 0; i < width * height; i++) {
|
|
|
- initialData.put((byte) 0x00);
|
|
|
- initialData.put((byte) 0xff);
|
|
|
- initialData.put((byte) 0x00);
|
|
|
- initialData.put((byte) 0xff);
|
|
|
- }
|
|
|
return atlasId;
|
|
|
} catch (Exception e) {
|
|
|
log.log(Level.WARNING, e.getMessage(), e);
|
|
@@ -368,10 +371,7 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
|
|
|
|
|
|
// internal implementations
|
|
|
private Texture2D createAtlasTextureInternal(final int width, final int height) throws Exception {
|
|
|
- ByteBuffer initialData = BufferUtils.createByteBuffer(width * height * 4);
|
|
|
- for (int i = 0; i < width * height * 4; i++) {
|
|
|
- initialData.put((byte) 0x00);
|
|
|
- }
|
|
|
+ // re-use pre-defined initial data instead of creating a new buffer
|
|
|
initialData.rewind();
|
|
|
|
|
|
Texture2D texture = new Texture2D(new com.jme3.texture.Image(Format.RGBA8, width, height, initialData, ColorSpace.sRGB));
|