/* * Copyright (c) 2009-2018 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.niftygui; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.ShortBuffer; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import com.jme3.asset.TextureKey; import com.jme3.material.Material; import com.jme3.material.RenderState; import com.jme3.math.Matrix4f; import com.jme3.renderer.RenderManager; import com.jme3.renderer.Renderer; import com.jme3.scene.Geometry; import com.jme3.scene.Mesh; import com.jme3.scene.VertexBuffer; import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Usage; import com.jme3.texture.Image.Format; import com.jme3.texture.Texture.MagFilter; import com.jme3.texture.Texture.MinFilter; import com.jme3.texture.Texture2D; import com.jme3.texture.image.ColorSpace; import com.jme3.util.BufferUtils; import de.lessvoid.nifty.render.batch.spi.BatchRenderBackend; import de.lessvoid.nifty.render.BlendMode; import de.lessvoid.nifty.spi.render.MouseCursor; import de.lessvoid.nifty.tools.Color; import de.lessvoid.nifty.tools.Factory; import de.lessvoid.nifty.tools.ObjectPool; import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader; import java.util.HashMap; import java.util.Map; /** * Nifty GUI BatchRenderBackend Implementation for jMonkeyEngine. * @author void */ public class JmeBatchRenderBackend implements BatchRenderBackend { private static Logger log = Logger.getLogger(JmeBatchRenderBackend.class.getName()); private final ObjectPool batchPool; private final List batches = new ArrayList(); // a modify texture call needs a jme Renderer to execute. if we're called to modify a texture but don't // have a Renderer yet - since it was not initialized on the jme side - we'll cache the modify texture calls // in here and execute them later (at the next beginFrame() call). private final List modifyTextureCalls = new ArrayList(); private RenderManager renderManager; private NiftyJmeDisplay display; private Map textures = new HashMap(); private int textureAtlasId = 1; private Batch currentBatch; private Matrix4f tempMat = new Matrix4f(); private ByteBuffer initialData; // 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 // removed since it's now possible to configure it using the // BatchRenderConfiguration class when you create the NiftyJmeDisplay instance private boolean fillRemovedTexture = false; public JmeBatchRenderBackend(final NiftyJmeDisplay display) { this.display = display; this.batchPool = new ObjectPool(new Factory() { @Override public Batch createNew() { return new Batch(); } }); } public void setRenderManager(final RenderManager rm) { this.renderManager = rm; } @Override public void setResourceLoader(final NiftyResourceLoader resourceLoader) { } @Override public int getWidth() { return display.getWidth(); } @Override public int getHeight() { return display.getHeight(); } @Override public void beginFrame() { log.fine("beginFrame()"); for (int i=0; i