From 4717e7006f39390ae07c0562f848a224f0b03a56 Mon Sep 17 00:00:00 2001 From: shadowislord Date: Sun, 9 Nov 2014 12:29:28 -0500 Subject: [PATCH] Goodbye, OpenGL1 --- .../com/jme3/material/FixedFuncBinding.java | 85 -- .../main/java/com/jme3/material/MatParam.java | 23 +- .../com/jme3/material/MatParamTexture.java | 4 +- .../main/java/com/jme3/material/Material.java | 9 +- .../java/com/jme3/material/MaterialDef.java | 5 +- .../java/com/jme3/renderer/GL1Renderer.java | 57 - .../java/com/jme3/system/AppSettings.java | 18 - .../com/jme3/material/plugins/J3MLoader.java | 10 +- .../jme3/renderer/jogl/JoglGL1Renderer.java | 1261 ----------------- .../jme3/renderer/lwjgl/LwjglGL1Renderer.java | 1208 ---------------- .../com/jme3/system/lwjgl/LwjglContext.java | 30 +- .../gde/core/editor/SceneApplication.java | 3 - .../jme3/gde/core/scene/SceneApplication.java | 3 - 13 files changed, 23 insertions(+), 2693 deletions(-) delete mode 100644 jme3-core/src/main/java/com/jme3/material/FixedFuncBinding.java delete mode 100644 jme3-core/src/main/java/com/jme3/renderer/GL1Renderer.java delete mode 100644 jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglGL1Renderer.java delete mode 100644 jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java diff --git a/jme3-core/src/main/java/com/jme3/material/FixedFuncBinding.java b/jme3-core/src/main/java/com/jme3/material/FixedFuncBinding.java deleted file mode 100644 index c28186a4a..000000000 --- a/jme3-core/src/main/java/com/jme3/material/FixedFuncBinding.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2009-2012 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.material; - -/** - * Fixed function binding is used to specify a binding for a {@link MatParam} - * in case that shaders are not supported on the system. - * - * @author Kirill Vainer - */ -public enum FixedFuncBinding { - /** - * Specifies the material ambient color. - * Same as GL_AMBIENT for OpenGL. - */ - MaterialAmbient, - - /** - * Specifies the material diffuse color. - * Same as GL_DIFFUSE for OpenGL. - */ - MaterialDiffuse, - - /** - * Specifies the material specular color. - * Same as GL_SPECULAR for OpenGL - */ - MaterialSpecular, - - /** - * Specifies the color of the object. - *

- * Used only for non-lit materials. - */ - Color, - - /** - * Specifies the material shininess value. - * - * Same as GL_SHININESS for OpenGL. - */ - MaterialShininess, - - /** - * Use vertex color as an additional diffuse color, if lighting is enabled. - * If lighting is disabled, vertex color is modulated with - * {@link #Color material color}. - */ - UseVertexColor, - - /** - * Set the alpha threshold to discard pixels. - * @see RenderState#setAlphaFallOff - */ - AlphaTestFallOff -} diff --git a/jme3-core/src/main/java/com/jme3/material/MatParam.java b/jme3-core/src/main/java/com/jme3/material/MatParam.java index 42abf49c6..9088b5b47 100644 --- a/jme3-core/src/main/java/com/jme3/material/MatParam.java +++ b/jme3-core/src/main/java/com/jme3/material/MatParam.java @@ -34,7 +34,6 @@ package com.jme3.material; import com.jme3.asset.TextureKey; import com.jme3.export.*; import com.jme3.math.*; -import com.jme3.renderer.GL1Renderer; import com.jme3.renderer.Renderer; import com.jme3.shader.VarType; import com.jme3.texture.Texture; @@ -53,17 +52,15 @@ public class MatParam implements Savable, Cloneable { protected String name; protected String prefixedName; protected Object value; - protected FixedFuncBinding ffBinding; /** * Create a new material parameter. For internal use only. */ - public MatParam(VarType type, String name, Object value, FixedFuncBinding ffBinding) { + public MatParam(VarType type, String name, Object value) { this.type = type; this.name = name; this.prefixedName = "m_" + name; this.value = value; - this.ffBinding = ffBinding; } /** @@ -72,15 +69,6 @@ public class MatParam implements Savable, Cloneable { public MatParam() { } - /** - * Returns the fixed function binding. - * - * @return the fixed function binding. - */ - public FixedFuncBinding getFixedFuncBinding() { - return ffBinding; - } - /** * Returns the material parameter type. * @@ -146,9 +134,6 @@ public class MatParam implements Savable, Cloneable { if (techDef.isUsingShaders()) { technique.updateUniformParam(getPrefixedName(), getVarType(), getValue()); } - if (ffBinding != null && r instanceof GL1Renderer) { - ((GL1Renderer) r).setFixedFuncBinding(ffBinding, getValue()); - } } /** @@ -290,7 +275,6 @@ When arrays can be inserted in J3M files OutputCapsule oc = ex.getCapsule(this); oc.write(type, "varType", null); oc.write(name, "name", null); - oc.write(ffBinding, "ff_binding", null); if (value instanceof Savable) { Savable s = (Savable) value; oc.write(s, "value_savable", null); @@ -311,7 +295,6 @@ When arrays can be inserted in J3M files type = ic.readEnum("varType", VarType.class, null); name = ic.readString("name", null); prefixedName = "m_" + name; - ffBinding = ic.readEnum("ff_binding", FixedFuncBinding.class, null); switch (getVarType()) { case Boolean: value = ic.readBoolean("value_bool", false); @@ -346,9 +329,6 @@ When arrays can be inserted in J3M files if (this.value != other.value && (this.value == null || !this.value.equals(other.value))) { return false; } - if (this.ffBinding != other.ffBinding) { - return false; - } return true; } @@ -358,7 +338,6 @@ When arrays can be inserted in J3M files hash = 59 * hash + (this.type != null ? this.type.hashCode() : 0); hash = 59 * hash + (this.name != null ? this.name.hashCode() : 0); hash = 59 * hash + (this.value != null ? this.value.hashCode() : 0); - hash = 59 * hash + (this.ffBinding != null ? this.ffBinding.hashCode() : 0); return hash; } diff --git a/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java b/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java index 83db2ab6b..1a211b475 100644 --- a/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java +++ b/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java @@ -48,13 +48,13 @@ public class MatParamTexture extends MatParam { private ColorSpace colorSpace; public MatParamTexture(VarType type, String name, Texture texture, int unit) { - super(type, name, texture, null); + super(type, name, texture); this.texture = texture; this.unit = unit; } public MatParamTexture(VarType type, String name, Texture texture, int unit, ColorSpace colorSpace) { - super(type, name, texture, null); + super(type, name, texture); this.texture = texture; this.unit = unit; this.colorSpace = colorSpace; diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java index 158035dc9..3299f3624 100644 --- a/jme3-core/src/main/java/com/jme3/material/Material.java +++ b/jme3-core/src/main/java/com/jme3/material/Material.java @@ -480,7 +480,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { MatParam val = getParam(name); if (val == null) { MatParam paramDef = def.getMaterialParam(name); - paramValues.put(name, new MatParam(type, name, value, paramDef.getFixedFuncBinding())); + paramValues.put(name, new MatParam(type, name, value)); } else { val.setValue(value); } @@ -1089,7 +1089,12 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { for (int i = 0; i < size; i++) { Uniform u = uniforms.getValue(i); if (!u.isSetByCurrentMaterial()) { - u.clearValue(); + if (u.getName().charAt(0) != 'g') { + // Don't reset world globals! + // The benefits gained from this are very minimal + // and cause lots of matrix -> FloatBuffer conversions. + u.clearValue(); + } } } } diff --git a/jme3-core/src/main/java/com/jme3/material/MaterialDef.java b/jme3-core/src/main/java/com/jme3/material/MaterialDef.java index 8a85eacd0..47d672f3b 100644 --- a/jme3-core/src/main/java/com/jme3/material/MaterialDef.java +++ b/jme3-core/src/main/java/com/jme3/material/MaterialDef.java @@ -119,10 +119,9 @@ public class MaterialDef { * @param type Type of the parameter * @param name Name of the parameter * @param value Default value of the parameter - * @param ffBinding Fixed function binding for the parameter */ - public void addMaterialParam(VarType type, String name, Object value, FixedFuncBinding ffBinding) { - matParams.put(name, new MatParam(type, name, value, ffBinding)); + public void addMaterialParam(VarType type, String name, Object value) { + matParams.put(name, new MatParam(type, name, value)); } /** diff --git a/jme3-core/src/main/java/com/jme3/renderer/GL1Renderer.java b/jme3-core/src/main/java/com/jme3/renderer/GL1Renderer.java deleted file mode 100644 index 9e626e791..000000000 --- a/jme3-core/src/main/java/com/jme3/renderer/GL1Renderer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2009-2012 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.renderer; - -import com.jme3.material.FixedFuncBinding; - -/** - * Renderer sub-interface that is used for non-shader based renderers. - *

- * The GL1Renderer provides a single call, - * {@link #setFixedFuncBinding(com.jme3.material.FixedFuncBinding, java.lang.Object) } - * which allows to set fixed functionality state. - * - * @author Kirill Vainer - */ -public interface GL1Renderer extends Renderer { - - /** - * Set the fixed functionality state. - *

- * See {@link FixedFuncBinding} for various values that - * can be set. - * - * @param ffBinding The binding to set - * @param val The value - */ - public void setFixedFuncBinding(FixedFuncBinding ffBinding, Object val); -} diff --git a/jme3-core/src/main/java/com/jme3/system/AppSettings.java b/jme3-core/src/main/java/com/jme3/system/AppSettings.java index 69cbb8760..e8ed74092 100644 --- a/jme3-core/src/main/java/com/jme3/system/AppSettings.java +++ b/jme3-core/src/main/java/com/jme3/system/AppSettings.java @@ -56,13 +56,6 @@ public final class AppSettings extends HashMap { private static final AppSettings defaults = new AppSettings(false); - /** - * Use LWJGL as the display system and force using the OpenGL1.1 renderer. - * - * @see AppSettings#setRenderer(java.lang.String) - */ - public static final String LWJGL_OPENGL1 = "LWJGL-OPENGL1"; - /** * Use LWJGL as the display system and force using the OpenGL2.0 renderer. *

@@ -87,17 +80,6 @@ public final class AppSettings extends HashMap { */ public static final String LWJGL_OPENGL3 = "LWJGL-OpenGL3"; - /** - * Use LWJGL as the display system and allow the context - * to choose an appropriate renderer based on system capabilities. - *

- * If the GPU supports OpenGL2 or later, then the OpenGL2.0 renderer will - * be used, otherwise, the OpenGL1.1 renderer is used. - * - * @see AppSettings#setRenderer(java.lang.String) - */ - public static final String LWJGL_OPENGL_ANY = "LWJGL-OpenGL-Any"; - /** * Use the LWJGL OpenAL based renderer for audio capabilities. * diff --git a/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java b/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java index 0a2139363..7a9903e09 100644 --- a/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java +++ b/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java @@ -221,7 +221,6 @@ public class J3MLoader implements AssetLoader { private void readParam(String statement) throws IOException{ String name; String defaultVal = null; - FixedFuncBinding ffBinding = null; ColorSpace colorSpace = null; String[] split = statement.split("-"); @@ -251,12 +250,7 @@ public class J3MLoader implements AssetLoader { // get content inside parentheses int endParen = statement.indexOf(")", startParen); String bindingStr = statement.substring(startParen+1, endParen).trim(); - try { - ffBinding = FixedFuncBinding.valueOf(bindingStr); - } catch (IllegalArgumentException ex){ - throw new IOException("FixedFuncBinding '" + - split[1] + "' does not exist!"); - } + // don't care about bindingStr statement = statement.substring(0, startParen); } @@ -282,7 +276,7 @@ public class J3MLoader implements AssetLoader { if(type.isTextureType()){ materialDef.addMaterialParamTexture(type, name, colorSpace); }else{ - materialDef.addMaterialParam(type, name, defaultValObj, ffBinding); + materialDef.addMaterialParam(type, name, defaultValObj); } } diff --git a/jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglGL1Renderer.java b/jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglGL1Renderer.java deleted file mode 100644 index 22a4d3143..000000000 --- a/jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglGL1Renderer.java +++ /dev/null @@ -1,1261 +0,0 @@ -/* - * Copyright (c) 2009-2012 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.renderer.jogl; - -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.media.opengl.GL; -import javax.media.opengl.GL2; -import javax.media.opengl.GL2ES1; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GL2GL3; -import javax.media.opengl.GLContext; -import javax.media.opengl.fixedfunc.GLLightingFunc; -import javax.media.opengl.fixedfunc.GLMatrixFunc; -import javax.media.opengl.fixedfunc.GLPointerFunc; - -import jme3tools.converters.MipMapGenerator; - -import com.jme3.light.DirectionalLight; -import com.jme3.light.Light; -import com.jme3.light.LightList; -import com.jme3.light.PointLight; -import com.jme3.light.SpotLight; -import com.jme3.material.FixedFuncBinding; -import com.jme3.material.RenderState; -import com.jme3.math.ColorRGBA; -import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; -import com.jme3.math.Vector3f; -import com.jme3.renderer.Caps; -import com.jme3.renderer.GL1Renderer; -import com.jme3.renderer.RenderContext; -import com.jme3.renderer.RendererException; -import com.jme3.renderer.Statistics; -import com.jme3.scene.Mesh; -import com.jme3.scene.Mesh.Mode; -import com.jme3.scene.VertexBuffer; -import com.jme3.scene.VertexBuffer.Type; -import com.jme3.scene.VertexBuffer.Usage; -import com.jme3.shader.Shader; -import com.jme3.shader.Shader.ShaderSource; -import com.jme3.texture.FrameBuffer; -import com.jme3.texture.Image; -import com.jme3.texture.Texture; -import com.jme3.texture.Texture.WrapAxis; -import com.jme3.util.BufferUtils; -import com.jme3.util.NativeObjectManager; - -public class JoglGL1Renderer implements GL1Renderer { - - private static final Logger logger = Logger.getLogger(JoglRenderer.class.getName()); - private final ByteBuffer nameBuf = BufferUtils.createByteBuffer(250); - private final StringBuilder stringBuf = new StringBuilder(250); - private final IntBuffer ib1 = BufferUtils.createIntBuffer(1); - private final IntBuffer intBuf16 = BufferUtils.createIntBuffer(16); - private final FloatBuffer fb16 = BufferUtils.createFloatBuffer(16); - private final FloatBuffer fb4Null = BufferUtils.createFloatBuffer(4); - private final RenderContext context = new RenderContext(); - private final NativeObjectManager objManager = new NativeObjectManager(); - private final EnumSet caps = EnumSet.noneOf(Caps.class); - private int maxTexSize; - private int maxCubeTexSize; - private int maxVertCount; - private int maxTriCount; - private int maxLights; - private boolean gl12 = false; - private final Statistics statistics = new Statistics(); - private int vpX, vpY, vpW, vpH; - private int clipX, clipY, clipW, clipH; - - private Matrix4f worldMatrix = new Matrix4f(); - private Matrix4f viewMatrix = new Matrix4f(); - - private ArrayList lightList = new ArrayList(8); - private ColorRGBA materialAmbientColor = new ColorRGBA(); - private Vector3f tempVec = new Vector3f(); - - protected void updateNameBuffer() { - int len = stringBuf.length(); - - nameBuf.position(0); - nameBuf.limit(len); - for (int i = 0; i < len; i++) { - nameBuf.put((byte) stringBuf.charAt(i)); - } - - nameBuf.rewind(); - } - - public Statistics getStatistics() { - return statistics; - } - - public EnumSet getCaps() { - return caps; - } - - public void initialize() { - GL gl = GLContext.getCurrentGL(); - if (gl.isExtensionAvailable("GL_VERSION_1_2")){ - gl12 = true; - } - - //workaround, always assume we support GLSL100 - //some cards just don't report this correctly - caps.add(Caps.GLSL100); - - // Default values for certain GL state. - gl.getGL2ES1().glShadeModel(GLLightingFunc.GL_SMOOTH); - gl.getGL2().glColorMaterial(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_DIFFUSE); - gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); - - // Enable rescaling/normaling of normal vectors. - // Fixes lighting issues with scaled models. - if (gl12){ - gl.glEnable(GL2ES1.GL_RESCALE_NORMAL); - }else{ - gl.glEnable(GLLightingFunc.GL_NORMALIZE); - } - - if (gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two")) { - caps.add(Caps.NonPowerOfTwoTextures); - } else { - logger.log(Level.WARNING, "Your graphics card does not " - + "support non-power-of-2 textures. " - + "Some features might not work."); - } - - gl.glGetIntegerv(GL2ES1.GL_MAX_LIGHTS, ib1); - maxLights = ib1.get(0); - - gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, ib1); - maxTexSize = ib1.get(0); - } - - public void invalidateState() { - context.reset(); - } - - public void resetGLObjects() { - logger.log(Level.FINE, "Reseting objects and invalidating state"); - objManager.resetObjects(); - statistics.clearMemory(); - invalidateState(); - } - - public void cleanup() { - logger.log(Level.FINE, "Deleting objects and invalidating state"); - objManager.deleteAllObjects(this); - statistics.clearMemory(); - invalidateState(); - } - - public void setDepthRange(float start, float end) { - GL gl = GLContext.getCurrentGL(); - gl.getGL2ES2().glDepthRange(start, end); - } - - public void clearBuffers(boolean color, boolean depth, boolean stencil) { - GL gl = GLContext.getCurrentGL(); - int bits = 0; - if (color) { - //See explanations of the depth below, we must enable color write to be able to clear the color buffer - if (context.colorWriteEnabled == false) { - gl.glColorMask(true, true, true, true); - context.colorWriteEnabled = true; - } - bits = GL.GL_COLOR_BUFFER_BIT; - } - if (depth) { - - //glClear(GL_DEPTH_BUFFER_BIT) seems to not work when glDepthMask is false - //here s some link on openl board - //http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=257223 - //if depth clear is requested, we enable the depthMask - if (context.depthWriteEnabled == false) { - gl.glDepthMask(true); - context.depthWriteEnabled = true; - } - bits |= GL.GL_DEPTH_BUFFER_BIT; - } - if (stencil) { - bits |= GL.GL_STENCIL_BUFFER_BIT; - } - if (bits != 0) { - gl.glClear(bits); - } - } - - public void setBackgroundColor(ColorRGBA color) { - GL gl = GLContext.getCurrentGL(); - gl.glClearColor(color.r, color.g, color.b, color.a); - } - - private void setMaterialColor(int type, ColorRGBA color, ColorRGBA defaultColor) { - GL gl = GLContext.getCurrentGL(); - if (color != null){ - fb16.put(color.r).put(color.g).put(color.b).put(color.a).flip(); - }else{ - fb16.put(defaultColor.r).put(defaultColor.g).put(defaultColor.b).put(defaultColor.a).flip(); - } - gl.getGL2().glMaterialfv(GL.GL_FRONT_AND_BACK, type, fb16); - } - - /** - * Applies fixed function bindings from the context to OpenGL - */ - private void applyFixedFuncBindings(boolean forLighting){ - GL gl = GLContext.getCurrentGL(); - if (forLighting) { - gl.getGL2().glMaterialf(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SHININESS, context.shininess); - setMaterialColor(GLLightingFunc.GL_AMBIENT, context.ambient, ColorRGBA.DarkGray); - setMaterialColor(GLLightingFunc.GL_DIFFUSE, context.diffuse, ColorRGBA.White); - setMaterialColor(GLLightingFunc.GL_SPECULAR, context.specular, ColorRGBA.Black); - - if (context.useVertexColor) { - gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL); - } else { - gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL); - } - } else { - // Ignore other values as they have no effect when - // GL_LIGHTING is disabled. - ColorRGBA color = context.color; - if (color != null) { - gl.getGL2().glColor4f(color.r, color.g, color.b, color.a); - } else { - gl.getGL2().glColor4f(1, 1, 1, 1); - } - } - if (context.alphaTestFallOff > 0f) { - gl.glEnable(GL2ES1.GL_ALPHA_TEST); - gl.getGL2ES1().glAlphaFunc(GL.GL_GREATER, context.alphaTestFallOff); - } else { - gl.glDisable(GL2ES1.GL_ALPHA_TEST); - } - } - - /** - * Reset fixed function bindings to default values. - */ - private void resetFixedFuncBindings(){ - context.alphaTestFallOff = 0f; // zero means disable alpha test! - context.color = null; - context.ambient = null; - context.diffuse = null; - context.specular = null; - context.shininess = 0; - context.useVertexColor = false; - } - - public void setFixedFuncBinding(FixedFuncBinding ffBinding, Object val) { - switch (ffBinding) { - case Color: - context.color = (ColorRGBA) val; - break; - case MaterialAmbient: - context.ambient = (ColorRGBA) val; - break; - case MaterialDiffuse: - context.diffuse = (ColorRGBA) val; - break; - case MaterialSpecular: - context.specular = (ColorRGBA) val; - break; - case MaterialShininess: - context.shininess = (Float) val; - break; - case UseVertexColor: - context.useVertexColor = (Boolean) val; - break; - case AlphaTestFallOff: - context.alphaTestFallOff = (Float) val; - break; - } - } - - public void applyRenderState(RenderState state) { - GL gl = GLContext.getCurrentGL(); - if (state.isWireframe() && !context.wireframe) { - gl.getGL2GL3().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE); - context.wireframe = true; - } else if (!state.isWireframe() && context.wireframe) { - gl.getGL2GL3().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL); - context.wireframe = false; - } - - if (state.isDepthTest() && !context.depthTestEnabled) { - gl.glEnable(GL.GL_DEPTH_TEST); - gl.glDepthFunc(GL.GL_LEQUAL); - context.depthTestEnabled = true; - } else if (!state.isDepthTest() && context.depthTestEnabled) { - gl.glDisable(GL.GL_DEPTH_TEST); - context.depthTestEnabled = false; - } - - if (state.isAlphaTest()) { - setFixedFuncBinding(FixedFuncBinding.AlphaTestFallOff, state.getAlphaFallOff()); - } else { - setFixedFuncBinding(FixedFuncBinding.AlphaTestFallOff, 0f); // disable it - } - - if (state.isDepthWrite() && !context.depthWriteEnabled) { - gl.glDepthMask(true); - context.depthWriteEnabled = true; - } else if (!state.isDepthWrite() && context.depthWriteEnabled) { - gl.glDepthMask(false); - context.depthWriteEnabled = false; - } - - if (state.isColorWrite() && !context.colorWriteEnabled) { - gl.glColorMask(true, true, true, true); - context.colorWriteEnabled = true; - } else if (!state.isColorWrite() && context.colorWriteEnabled) { - gl.glColorMask(false, false, false, false); - context.colorWriteEnabled = false; - } - - if (state.isPointSprite()) { - logger.log(Level.WARNING, "Point Sprite unsupported!"); - } - - if (state.isPolyOffset()) { - if (!context.polyOffsetEnabled) { - gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); - gl.glPolygonOffset(state.getPolyOffsetFactor(), - state.getPolyOffsetUnits()); - context.polyOffsetEnabled = true; - context.polyOffsetFactor = state.getPolyOffsetFactor(); - context.polyOffsetUnits = state.getPolyOffsetUnits(); - } else { - if (state.getPolyOffsetFactor() != context.polyOffsetFactor - || state.getPolyOffsetUnits() != context.polyOffsetUnits) { - gl.glPolygonOffset(state.getPolyOffsetFactor(), - state.getPolyOffsetUnits()); - context.polyOffsetFactor = state.getPolyOffsetFactor(); - context.polyOffsetUnits = state.getPolyOffsetUnits(); - } - } - } else { - if (context.polyOffsetEnabled) { - gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); - context.polyOffsetEnabled = false; - context.polyOffsetFactor = 0; - context.polyOffsetUnits = 0; - } - } - if (state.getFaceCullMode() != context.cullMode) { - if (state.getFaceCullMode() == RenderState.FaceCullMode.Off) { - gl.glDisable(GL.GL_CULL_FACE); - } else { - gl.glEnable(GL.GL_CULL_FACE); - } - - switch (state.getFaceCullMode()) { - case Off: - break; - case Back: - gl.glCullFace(GL.GL_BACK); - break; - case Front: - gl.glCullFace(GL.GL_FRONT); - break; - case FrontAndBack: - gl.glCullFace(GL.GL_FRONT_AND_BACK); - break; - default: - throw new UnsupportedOperationException("Unrecognized face cull mode: " - + state.getFaceCullMode()); - } - - context.cullMode = state.getFaceCullMode(); - } - - if (state.getBlendMode() != context.blendMode) { - if (state.getBlendMode() == RenderState.BlendMode.Off) { - gl.glDisable(GL.GL_BLEND); - } else { - gl.glEnable(GL.GL_BLEND); - switch (state.getBlendMode()) { - case Off: - break; - case Additive: - gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE); - break; - case AlphaAdditive: - gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); - break; - case Color: - gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_COLOR); - break; - case Alpha: - gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); - break; - case PremultAlpha: - gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); - break; - case Modulate: - gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_ZERO); - break; - case ModulateX2: - gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_SRC_COLOR); - break; - default: - throw new UnsupportedOperationException("Unrecognized blend mode: " - + state.getBlendMode()); - } - } - - context.blendMode = state.getBlendMode(); - } - - if (state.isStencilTest()) { - throw new UnsupportedOperationException("OpenGL 1.1 doesn't support two sided stencil operations."); - } - - } - - public void setViewPort(int x, int y, int w, int h) { - if (x != vpX || vpY != y || vpW != w || vpH != h) { - GL gl = GLContext.getCurrentGL(); - gl.glViewport(x, y, w, h); - vpX = x; - vpY = y; - vpW = w; - vpH = h; - } - } - - public void setClipRect(int x, int y, int width, int height) { - GL gl = GLContext.getCurrentGL(); - if (!context.clipRectEnabled) { - gl.glEnable(GL.GL_SCISSOR_TEST); - context.clipRectEnabled = true; - } - if (clipX != x || clipY != y || clipW != width || clipH != height) { - gl.glScissor(x, y, width, height); - clipX = x; - clipY = y; - clipW = width; - clipH = height; - } - } - - public void clearClipRect() { - GL gl = GLContext.getCurrentGL(); - if (context.clipRectEnabled) { - gl.glDisable(GL.GL_SCISSOR_TEST); - context.clipRectEnabled = false; - - clipX = 0; - clipY = 0; - clipW = 0; - clipH = 0; - } - } - - public void onFrame() { - objManager.deleteUnused(this); -// statistics.clearFrame(); - } - - private FloatBuffer storeMatrix(Matrix4f matrix, FloatBuffer store) { - store.clear(); - matrix.fillFloatBuffer(store, true); - store.clear(); - return store; - } - - private void setModelView(Matrix4f modelMatrix, Matrix4f viewMatrix){ - GL gl = GLContext.getCurrentGL(); - if (context.matrixMode != GLMatrixFunc.GL_MODELVIEW) { - gl.getGL2ES1().glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - context.matrixMode = GLMatrixFunc.GL_MODELVIEW; - } - - gl.getGL2ES1().glLoadMatrixf(storeMatrix(viewMatrix, fb16)); - gl.getGL2ES1().glMultMatrixf(storeMatrix(modelMatrix, fb16)); - } - - private void setProjection(Matrix4f projMatrix){ - GL gl = GLContext.getCurrentGL(); - if (context.matrixMode != GLMatrixFunc.GL_PROJECTION) { - gl.getGL2ES1().glMatrixMode(GLMatrixFunc.GL_PROJECTION); - context.matrixMode = GLMatrixFunc.GL_PROJECTION; - } - - gl.getGL2ES1().glLoadMatrixf(storeMatrix(projMatrix, fb16)); - } - - public void setWorldMatrix(Matrix4f worldMatrix) { - this.worldMatrix.set(worldMatrix); - } - - public void setViewProjectionMatrices(Matrix4f viewMatrix, Matrix4f projMatrix) { - this.viewMatrix.set(viewMatrix); - setProjection(projMatrix); - } - - public void setLighting(LightList list) { - GL gl = GLContext.getCurrentGL(); - // XXX: This is abuse of setLighting() to - // apply fixed function bindings - // and do other book keeping. - if (list == null || list.size() == 0){ - gl.glDisable(GLLightingFunc.GL_LIGHTING); - applyFixedFuncBindings(false); - setModelView(worldMatrix, viewMatrix); - return; - } - - // Number of lights set previously - int numLightsSetPrev = lightList.size(); - - // If more than maxLights are defined, they will be ignored. - // The GL1 renderer is not permitted to crash due to a - // GL1 limitation. It must render anything that the GL2 renderer - // can render (even incorrectly). - lightList.clear(); - materialAmbientColor.set(0, 0, 0, 0); - - for (int i = 0; i < list.size(); i++){ - Light l = list.get(i); - if (l.getType() == Light.Type.Ambient){ - // Gather - materialAmbientColor.addLocal(l.getColor()); - }else{ - // Add to list - lightList.add(l); - - // Once maximum lights reached, exit loop. - if (lightList.size() >= maxLights){ - break; - } - } - } - - applyFixedFuncBindings(true); - - gl.glEnable(GLLightingFunc.GL_LIGHTING); - - fb16.clear(); - fb16.put(materialAmbientColor.r) - .put(materialAmbientColor.g) - .put(materialAmbientColor.b) - .put(1).flip(); - - gl.getGL2ES1().glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT, fb16); - - if (context.matrixMode != GLMatrixFunc.GL_MODELVIEW) { - gl.getGL2ES1().glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - context.matrixMode = GLMatrixFunc.GL_MODELVIEW; - } - // Lights are already in world space, so just convert - // them to view space. - gl.getGL2ES1().glLoadMatrixf(storeMatrix(viewMatrix, fb16)); - - for (int i = 0; i < lightList.size(); i++){ - int glLightIndex = GLLightingFunc.GL_LIGHT0 + i; - Light light = lightList.get(i); - Light.Type lightType = light.getType(); - ColorRGBA col = light.getColor(); - Vector3f pos; - - // Enable the light - gl.glEnable(glLightIndex); - - // OGL spec states default value for light ambient is black - switch (lightType){ - case Directional: - DirectionalLight dLight = (DirectionalLight) light; - - fb16.clear(); - fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip(); - gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_DIFFUSE, fb16); - gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_SPECULAR, fb16); - - pos = tempVec.set(dLight.getDirection()).negateLocal().normalizeLocal(); - fb16.clear(); - fb16.put(pos.x).put(pos.y).put(pos.z).put(0.0f).flip(); - gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_POSITION, fb16); - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_SPOT_CUTOFF, 180); - break; - case Point: - PointLight pLight = (PointLight) light; - - fb16.clear(); - fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip(); - gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_DIFFUSE, fb16); - gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_SPECULAR, fb16); - - pos = pLight.getPosition(); - fb16.clear(); - fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip(); - gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_POSITION, fb16); - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_SPOT_CUTOFF, 180); - - if (pLight.getRadius() > 0) { - // Note: this doesn't follow the same attenuation model - // as the one used in the lighting shader. - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_CONSTANT_ATTENUATION, 1); - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_LINEAR_ATTENUATION, pLight.getInvRadius() * 2); - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_QUADRATIC_ATTENUATION, pLight.getInvRadius() * pLight.getInvRadius()); - }else{ - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_CONSTANT_ATTENUATION, 1); - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_LINEAR_ATTENUATION, 0); - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_QUADRATIC_ATTENUATION, 0); - } - - break; - case Spot: - SpotLight sLight = (SpotLight) light; - - fb16.clear(); - fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip(); - gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_DIFFUSE, fb16); - gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_SPECULAR, fb16); - - pos = sLight.getPosition(); - fb16.clear(); - fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip(); - gl.getGL2().glLightfv(glLightIndex, GLLightingFunc.GL_POSITION, fb16); - - Vector3f dir = sLight.getDirection(); - fb16.clear(); - fb16.put(dir.x).put(dir.y).put(dir.z).put(1.0f).flip(); - gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_SPOT_DIRECTION, fb16); - - float outerAngleRad = sLight.getSpotOuterAngle(); - float innerAngleRad = sLight.getSpotInnerAngle(); - float spotCut = outerAngleRad * FastMath.RAD_TO_DEG; - float spotExpo = 0.0f; - if (outerAngleRad > 0) { - spotExpo = (1.0f - (innerAngleRad / outerAngleRad)) * 128.0f; - } - - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_SPOT_CUTOFF, spotCut); - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_SPOT_EXPONENT, spotExpo); - - if (sLight.getSpotRange() > 0) { - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_LINEAR_ATTENUATION, sLight.getInvSpotRange()); - }else{ - gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_LINEAR_ATTENUATION, 0); - } - - break; - default: - throw new UnsupportedOperationException( - "Unrecognized light type: " + lightType); - } - } - - // Disable lights after the index - for (int i = lightList.size(); i < numLightsSetPrev; i++){ - gl.glDisable(GLLightingFunc.GL_LIGHT0 + i); - } - - // This will set view matrix as well. - setModelView(worldMatrix, viewMatrix); - } - - private int convertTextureType(Texture.Type type) { - switch (type) { - case TwoDimensional: - return GL.GL_TEXTURE_2D; -// case ThreeDimensional: -// return GL_TEXTURE_3D; -// case CubeMap: -// return GL_TEXTURE_CUBE_MAP; - default: - throw new UnsupportedOperationException("Unknown texture type: " + type); - } - } - - private int convertMagFilter(Texture.MagFilter filter) { - switch (filter) { - case Bilinear: - return GL.GL_LINEAR; - case Nearest: - return GL.GL_NEAREST; - default: - throw new UnsupportedOperationException("Unknown mag filter: " + filter); - } - } - - private int convertMinFilter(Texture.MinFilter filter) { - switch (filter) { - case Trilinear: - return GL.GL_LINEAR_MIPMAP_LINEAR; - case BilinearNearestMipMap: - return GL.GL_LINEAR_MIPMAP_NEAREST; - case NearestLinearMipMap: - return GL.GL_NEAREST_MIPMAP_LINEAR; - case NearestNearestMipMap: - return GL.GL_NEAREST_MIPMAP_NEAREST; - case BilinearNoMipMaps: - return GL.GL_LINEAR; - case NearestNoMipMaps: - return GL.GL_NEAREST; - default: - throw new UnsupportedOperationException("Unknown min filter: " + filter); - } - } - - private int convertWrapMode(Texture.WrapMode mode) { - switch (mode) { - case EdgeClamp: - case Clamp: - case BorderClamp: - return GL2.GL_CLAMP; - case Repeat: - return GL.GL_REPEAT; - default: - throw new UnsupportedOperationException("Unknown wrap mode: " + mode); - } - } - - private void setupTextureParams(Texture tex) { - int target = convertTextureType(tex.getType()); - - // filter things - int minFilter = convertMinFilter(tex.getMinFilter()); - int magFilter = convertMagFilter(tex.getMagFilter()); - GL gl = GLContext.getCurrentGL(); - gl.glTexParameteri(target, GL.GL_TEXTURE_MIN_FILTER, minFilter); - gl.glTexParameteri(target, GL.GL_TEXTURE_MAG_FILTER, magFilter); - - // repeat modes - switch (tex.getType()) { -// case ThreeDimensional: -// case CubeMap: -// glTexParameteri(target, GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R))); - case TwoDimensional: - gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T))); - // fall down here is intentional.. -// case OneDimensional: - gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S))); - break; - default: - throw new UnsupportedOperationException("Unknown texture type: " + tex.getType()); - } - } - - public void updateTexImageData(Image img, Texture.Type type, int unit) { - int texId = img.getId(); - GL gl = GLContext.getCurrentGL(); - if (texId == -1) { - // create texture - gl.glGenTextures(1, ib1); - texId = ib1.get(0); - img.setId(texId); - objManager.registerObject(img); - - statistics.onNewTexture(); - } - - // bind texture - int target = convertTextureType(type); -// if (context.boundTextureUnit != unit) { -// glActiveTexture(GL_TEXTURE0 + unit); -// context.boundTextureUnit = unit; -// } - if (context.boundTextures[unit] != img) { - gl.glEnable(target); - gl.glBindTexture(target, texId); - context.boundTextures[unit] = img; - - statistics.onTextureUse(img, true); - } - - // Check sizes if graphics card doesn't support NPOT - if (!gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two") && img.isNPOT()) { - // Resize texture to Power-of-2 size - MipMapGenerator.resizeToPowerOf2(img); - } - - if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) { - // No pregenerated mips available, - // generate from base level if required - - // Check if hardware mips are supported - if (gl.isExtensionAvailable("GL_VERSION_1_4")) { - gl.glTexParameteri(target, GL2ES1.GL_GENERATE_MIPMAP, GL.GL_TRUE); - } else { - MipMapGenerator.generateMipMaps(img); - } - img.setMipmapsGenerated(true); - } else { - } - - if (img.getWidth() > maxTexSize || img.getHeight() > maxTexSize) { - throw new RendererException("Cannot upload texture " + img + ". The maximum supported texture resolution is " + maxTexSize); - } - - /* - if (target == GL_TEXTURE_CUBE_MAP) { - List data = img.getData(); - if (data.size() != 6) { - logger.log(Level.WARNING, "Invalid texture: {0}\n" - + "Cubemap textures must contain 6 data units.", img); - return; - } - for (int i = 0; i < 6; i++) { - TextureUtil.uploadTexture(img, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, 0, tdc); - } - } else if (target == EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT) { - List data = img.getData(); - // -1 index specifies prepare data for 2D Array - TextureUtil.uploadTexture(img, target, -1, 0, tdc); - for (int i = 0; i < data.size(); i++) { - // upload each slice of 2D array in turn - // this time with the appropriate index - TextureUtil.uploadTexture(img, target, i, 0, tdc); - } - } else {*/ - TextureUtil.uploadTexture(img, target, 0, 0,false); - //} - - img.clearUpdateNeeded(); - } - - public void setTexture(int unit, Texture tex) { - if (unit != 0 || tex.getType() != Texture.Type.TwoDimensional) { - //throw new UnsupportedOperationException(); - return; - } - - Image image = tex.getImage(); - if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated()) ) { - updateTexImageData(image, tex.getType(), unit); - } - - int texId = image.getId(); - assert texId != -1; - - Image[] textures = context.boundTextures; - - int type = convertTextureType(tex.getType()); -// if (!context.textureIndexList.moveToNew(unit)) { -// if (context.boundTextureUnit != unit){ -// gl.glActiveTexture(GL.GL_TEXTURE0 + unit); -// context.boundTextureUnit = unit; -// } -// gl.glEnable(type); -// } - -// if (context.boundTextureUnit != unit) { -// gl.glActiveTexture(GL.GL_TEXTURE0 + unit); -// context.boundTextureUnit = unit; -// } - - if (textures[unit] != image) { - GL gl = GLContext.getCurrentGL(); - gl.glEnable(type); - gl.glBindTexture(type, texId); - textures[unit] = image; - - statistics.onTextureUse(image, true); - } else { - statistics.onTextureUse(image, false); - } - - setupTextureParams(tex); - } - - public void modifyTexture(Texture tex, Image pixels, int x, int y) { - setTexture(0, tex); - TextureUtil.uploadSubTexture(pixels, convertTextureType(tex.getType()), 0, x, y, false); - } - - private void clearTextureUnits() { - Image[] textures = context.boundTextures; - if (textures[0] != null) { - GL gl = GLContext.getCurrentGL(); - gl.glDisable(GL.GL_TEXTURE_2D); - textures[0] = null; - } - } - - public void deleteImage(Image image) { - int texId = image.getId(); - if (texId != -1) { - ib1.put(0, texId); - ib1.position(0).limit(1); - GL gl = GLContext.getCurrentGL(); - gl.glDeleteTextures(ib1.limit() ,ib1); - image.resetObject(); - } - } - - private int convertArrayType(VertexBuffer.Type type) { - switch (type) { - case Position: - return GLPointerFunc.GL_VERTEX_ARRAY; - case Normal: - return GLPointerFunc.GL_NORMAL_ARRAY; - case TexCoord: - return GLPointerFunc.GL_TEXTURE_COORD_ARRAY; - case Color: - return GLPointerFunc.GL_COLOR_ARRAY; - default: - return -1; // unsupported - } - } - - private int convertVertexFormat(VertexBuffer.Format fmt) { - switch (fmt) { - case Byte: - return GL.GL_BYTE; - case Float: - return GL.GL_FLOAT; - case Int: - return GL2ES2.GL_INT; - case Short: - return GL.GL_SHORT; - case UnsignedByte: - return GL.GL_UNSIGNED_BYTE; - case UnsignedInt: - return GL.GL_UNSIGNED_INT; - case UnsignedShort: - return GL.GL_UNSIGNED_SHORT; - default: - throw new UnsupportedOperationException("Unrecognized vertex format: " + fmt); - } - } - - private int convertElementMode(Mesh.Mode mode) { - switch (mode) { - case Points: - return GL.GL_POINTS; - case Lines: - return GL.GL_LINES; - case LineLoop: - return GL.GL_LINE_LOOP; - case LineStrip: - return GL.GL_LINE_STRIP; - case Triangles: - return GL.GL_TRIANGLES; - case TriangleFan: - return GL.GL_TRIANGLE_FAN; - case TriangleStrip: - return GL.GL_TRIANGLE_STRIP; - default: - throw new UnsupportedOperationException("Unrecognized mesh mode: " + mode); - } - } - - public void drawTriangleArray(Mesh.Mode mode, int count, int vertCount) { - if (count > 1) { - throw new UnsupportedOperationException(); - } - GL gl = GLContext.getCurrentGL(); - gl.glDrawArrays(convertElementMode(mode), 0, vertCount); - } - - public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) { - if (vb.getBufferType() == VertexBuffer.Type.Color && !context.useVertexColor) { - // Ignore vertex color buffer if vertex color is disabled. - return; - } - - int arrayType = convertArrayType(vb.getBufferType()); - if (arrayType == -1) { - return; // unsupported - } - GL gl = GLContext.getCurrentGL(); - gl.getGL2GL3().glEnableClientState(arrayType); - context.boundAttribs[vb.getBufferType().ordinal()] = vb; - - if (vb.getBufferType() == Type.Normal) { - // normalize if requested - if (vb.isNormalized() && !context.normalizeEnabled) { - gl.glEnable(GLLightingFunc.GL_NORMALIZE); - context.normalizeEnabled = true; - } else if (!vb.isNormalized() && context.normalizeEnabled) { - gl.glDisable(GLLightingFunc.GL_NORMALIZE); - context.normalizeEnabled = false; - } - } - - // NOTE: Use data from interleaved buffer if specified - Buffer data = idb != null ? idb.getData() : vb.getData(); - int comps = vb.getNumComponents(); - int type = convertVertexFormat(vb.getFormat()); - - data.rewind(); - - switch (vb.getBufferType()) { - case Position: - if (!(data instanceof FloatBuffer)) { - throw new UnsupportedOperationException(); - } - - gl.getGL2().glVertexPointer(comps, type, vb.getStride(), (FloatBuffer) data); - break; - case Normal: - if (!(data instanceof FloatBuffer)) { - throw new UnsupportedOperationException(); - } - - gl.getGL2().glNormalPointer(type, vb.getStride(), (FloatBuffer) data); - break; - case Color: - if (data instanceof FloatBuffer) { - gl.getGL2().glColorPointer(comps, type, vb.getStride(), (FloatBuffer) data); - } else if (data instanceof ByteBuffer) { - gl.getGL2().glColorPointer(comps, type, vb.getStride(), (ByteBuffer) data); - } else { - throw new UnsupportedOperationException(); - } - break; - case TexCoord: - if (!(data instanceof FloatBuffer)) { - throw new UnsupportedOperationException(); - } - - gl.getGL2().glTexCoordPointer(comps, type, vb.getStride(), (FloatBuffer) data); - break; - default: - // Ignore, this is an unsupported attribute for OpenGL1. - break; - } - } - - public void setVertexAttrib(VertexBuffer vb) { - setVertexAttrib(vb, null); - } - - private void drawElements(int mode, int format, Buffer data) { - GL gl = GLContext.getCurrentGL(); - switch (format) { - case GL.GL_UNSIGNED_BYTE: - gl.getGL2().glDrawElements(mode, data.limit(), format, (ByteBuffer) data); - break; - case GL.GL_UNSIGNED_SHORT: - gl.getGL2().glDrawElements(mode, data.limit(), format, (ShortBuffer) data); - break; - case GL.GL_UNSIGNED_INT: - gl.getGL2().glDrawElements(mode, data.limit(), format, (IntBuffer) data); - break; - default: - throw new UnsupportedOperationException(); - } - } - - public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) { - Mesh.Mode mode = mesh.getMode(); - - Buffer indexData = indexBuf.getData(); - indexData.rewind(); - - if (mesh.getMode() == Mode.Hybrid) { - throw new UnsupportedOperationException(); - /* - int[] modeStart = mesh.getModeStart(); - int[] elementLengths = mesh.getElementLengths(); - - int elMode = convertElementMode(Mode.Triangles); - int fmt = convertVertexFormat(indexBuf.getFormat()); - // int elSize = indexBuf.getFormat().getComponentSize(); - // int listStart = modeStart[0]; - int stripStart = modeStart[1]; - int fanStart = modeStart[2]; - int curOffset = 0; - for (int i = 0; i < elementLengths.length; i++) { - if (i == stripStart) { - elMode = convertElementMode(Mode.TriangleStrip); - } else if (i == fanStart) { - elMode = convertElementMode(Mode.TriangleStrip); - } - int elementLength = elementLengths[i]; - indexData.position(curOffset); - - drawElements(elMode, - fmt, - indexData); - - curOffset += elementLength; - }*/ - } else { - drawElements(convertElementMode(mode), - convertVertexFormat(indexBuf.getFormat()), - indexData); - } - } - - public void clearVertexAttribs() { - for (int i = 0; i < 16; i++) { - VertexBuffer vb = context.boundAttribs[i]; - if (vb != null) { - int arrayType = convertArrayType(vb.getBufferType()); - GL gl = GLContext.getCurrentGL(); - gl.getGL2().glDisableClientState(arrayType); - context.boundAttribs[vb.getBufferType().ordinal()] = null; - } - } - } - - private void renderMeshDefault(Mesh mesh, int lod, int count) { - VertexBuffer indices; - - VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); - if (interleavedData != null && interleavedData.isUpdateNeeded()) { - updateBufferData(interleavedData); - } - - if (mesh.getNumLodLevels() > 0) { - indices = mesh.getLodLevel(lod); - } else { - indices = mesh.getBuffer(Type.Index); - } - for (VertexBuffer vb : mesh.getBufferList().getArray()) { - if (vb.getBufferType() == Type.InterleavedData - || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers - || vb.getBufferType() == Type.Index) { - continue; - } - - if (vb.getStride() == 0) { - // not interleaved - setVertexAttrib(vb); - } else { - // interleaved - setVertexAttrib(vb, interleavedData); - } - } - - if (indices != null) { - drawTriangleList(indices, mesh, count); - } else { - GL gl = GLContext.getCurrentGL(); - gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); - } - - // TODO: Fix these to use IDList?? - clearVertexAttribs(); - clearTextureUnits(); - resetFixedFuncBindings(); - } - - public void renderMesh(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) { - if (mesh.getVertexCount() == 0) { - return; - } - GL gl = GLContext.getCurrentGL(); - if (context.pointSize != mesh.getPointSize()) { - gl.getGL2().glPointSize(mesh.getPointSize()); - context.pointSize = mesh.getPointSize(); - } - if (context.lineWidth != mesh.getLineWidth()) { - gl.getGL2().glLineWidth(mesh.getLineWidth()); - context.lineWidth = mesh.getLineWidth(); - } - - boolean dynamic = false; - if (mesh.getBuffer(Type.InterleavedData) != null) { - throw new UnsupportedOperationException("Interleaved meshes are not supported"); - } - - if (mesh.getNumLodLevels() == 0) { - for (VertexBuffer vb : mesh.getBufferList().getArray()) { - if (vb.getUsage() != VertexBuffer.Usage.Static) { - dynamic = true; - break; - } - } - } else { - dynamic = true; - } - - statistics.onMeshDrawn(mesh, lod); - -// if (!dynamic) { - // dealing with a static object, generate display list -// renderMeshDisplayList(mesh); -// } else { - renderMeshDefault(mesh, lod, count); -// } - - - } - - public void setAlphaToCoverage(boolean value) { - } - - public void setShader(Shader shader) { - } - - public void deleteShader(Shader shader) { - } - - public void deleteShaderSource(ShaderSource source) { - } - - public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst) { - } - - public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth) { - } - - public void setMainFrameBufferOverride(FrameBuffer fb){ - } - - public void setFrameBuffer(FrameBuffer fb) { - } - - public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) { - } - - public void deleteFrameBuffer(FrameBuffer fb) { - } - - public void updateBufferData(VertexBuffer vb) { - } - - public void deleteBuffer(VertexBuffer vb) { - } - - public void setMainFrameBufferSrgb(boolean srgb) { - } - - public void setLinearizeSrgbImages(boolean linearize) { - } -} diff --git a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java b/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java deleted file mode 100644 index af42dd5ee..000000000 --- a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java +++ /dev/null @@ -1,1208 +0,0 @@ -package com.jme3.renderer.lwjgl; - -import static org.lwjgl.opengl.GL11.*; - -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.logging.Level; -import java.util.logging.Logger; - -import jme3tools.converters.MipMapGenerator; - -import org.lwjgl.opengl.GL12; -import org.lwjgl.opengl.GL14; -import org.lwjgl.opengl.GLContext; - -import com.jme3.light.DirectionalLight; -import com.jme3.light.Light; -import com.jme3.light.LightList; -import com.jme3.light.PointLight; -import com.jme3.light.SpotLight; -import com.jme3.material.FixedFuncBinding; -import com.jme3.material.RenderState; -import com.jme3.math.ColorRGBA; -import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; -import com.jme3.math.Vector3f; -import com.jme3.renderer.Caps; -import com.jme3.renderer.GL1Renderer; -import com.jme3.renderer.RenderContext; -import com.jme3.renderer.RendererException; -import com.jme3.renderer.Statistics; -import com.jme3.scene.Mesh; -import com.jme3.scene.Mesh.Mode; -import com.jme3.scene.VertexBuffer; -import com.jme3.scene.VertexBuffer.Type; -import com.jme3.scene.VertexBuffer.Usage; -import com.jme3.shader.Shader; -import com.jme3.shader.Shader.ShaderSource; -import com.jme3.texture.FrameBuffer; -import com.jme3.texture.Image; -import com.jme3.texture.Texture; -import com.jme3.texture.Texture.WrapAxis; -import com.jme3.util.BufferUtils; -import com.jme3.util.NativeObjectManager; -import org.lwjgl.opengl.ContextCapabilities; - -public class LwjglGL1Renderer implements GL1Renderer { - - private static final Logger logger = Logger.getLogger(LwjglRenderer.class.getName()); - private final ByteBuffer nameBuf = BufferUtils.createByteBuffer(250); - private final StringBuilder stringBuf = new StringBuilder(250); - private final IntBuffer ib1 = BufferUtils.createIntBuffer(1); - private final IntBuffer intBuf16 = BufferUtils.createIntBuffer(16); - private final FloatBuffer fb16 = BufferUtils.createFloatBuffer(16); - private final FloatBuffer fb4Null = BufferUtils.createFloatBuffer(4); - private final RenderContext context = new RenderContext(); - private final NativeObjectManager objManager = new NativeObjectManager(); - private final EnumSet caps = EnumSet.noneOf(Caps.class); - private int maxTexSize; - private int maxCubeTexSize; - private int maxVertCount; - private int maxTriCount; - private int maxLights; - private boolean gl12 = false; - private final Statistics statistics = new Statistics(); - private int vpX, vpY, vpW, vpH; - private int clipX, clipY, clipW, clipH; - - private Matrix4f worldMatrix = new Matrix4f(); - private Matrix4f viewMatrix = new Matrix4f(); - - private ArrayList lightList = new ArrayList(8); - private ColorRGBA materialAmbientColor = new ColorRGBA(); - private Vector3f tempVec = new Vector3f(); - - private ContextCapabilities ctxCaps; - - protected void updateNameBuffer() { - int len = stringBuf.length(); - - nameBuf.position(0); - nameBuf.limit(len); - for (int i = 0; i < len; i++) { - nameBuf.put((byte) stringBuf.charAt(i)); - } - - nameBuf.rewind(); - } - - public Statistics getStatistics() { - return statistics; - } - - public EnumSet getCaps() { - return caps; - } - - public void initialize() { - ctxCaps = GLContext.getCapabilities(); - - if (ctxCaps.OpenGL12){ - gl12 = true; - } - - //workaround, always assume we support GLSL100 - //some cards just don't report this correctly - caps.add(Caps.GLSL100); - - // Default values for certain GL state. - glShadeModel(GL_SMOOTH); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - - // Enable rescaling/normaling of normal vectors. - // Fixes lighting issues with scaled models. - if (gl12){ - glEnable(GL12.GL_RESCALE_NORMAL); - }else{ - glEnable(GL_NORMALIZE); - } - - if (ctxCaps.GL_ARB_texture_non_power_of_two) { - caps.add(Caps.NonPowerOfTwoTextures); - } else { - logger.log(Level.WARNING, "Your graphics card does not " - + "support non-power-of-2 textures. " - + "Some features might not work."); - } - - maxLights = glGetInteger(GL_MAX_LIGHTS); - maxTexSize = glGetInteger(GL_MAX_TEXTURE_SIZE); - } - - public void invalidateState() { - context.reset(); - } - - public void resetGLObjects() { - logger.log(Level.FINE, "Reseting objects and invalidating state"); - objManager.resetObjects(); - statistics.clearMemory(); - invalidateState(); - } - - public void cleanup() { - logger.log(Level.FINE, "Deleting objects and invalidating state"); - objManager.deleteAllObjects(this); - statistics.clearMemory(); - invalidateState(); - } - - public void setDepthRange(float start, float end) { - glDepthRange(start, end); - } - - public void clearBuffers(boolean color, boolean depth, boolean stencil) { - int bits = 0; - if (color) { - //See explanations of the depth below, we must enable color write to be able to clear the color buffer - if (context.colorWriteEnabled == false) { - glColorMask(true, true, true, true); - context.colorWriteEnabled = true; - } - bits = GL_COLOR_BUFFER_BIT; - } - if (depth) { - - //glClear(GL_DEPTH_BUFFER_BIT) seems to not work when glDepthMask is false - //here s some link on openl board - //http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=257223 - //if depth clear is requested, we enable the depthMask - if (context.depthWriteEnabled == false) { - glDepthMask(true); - context.depthWriteEnabled = true; - } - bits |= GL_DEPTH_BUFFER_BIT; - } - if (stencil) { - bits |= GL_STENCIL_BUFFER_BIT; - } - if (bits != 0) { - glClear(bits); - } - } - - public void setBackgroundColor(ColorRGBA color) { - glClearColor(color.r, color.g, color.b, color.a); - } - - private void setMaterialColor(int type, ColorRGBA color, ColorRGBA defaultColor) { - if (color != null){ - fb16.put(color.r).put(color.g).put(color.b).put(color.a).flip(); - }else{ - fb16.put(defaultColor.r).put(defaultColor.g).put(defaultColor.b).put(defaultColor.a).flip(); - } - glMaterial(GL_FRONT_AND_BACK, type, fb16); - } - - /** - * Applies fixed function bindings from the context to OpenGL - */ - private void applyFixedFuncBindings(boolean forLighting){ - if (forLighting) { - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, context.shininess); - setMaterialColor(GL_AMBIENT, context.ambient, ColorRGBA.DarkGray); - setMaterialColor(GL_DIFFUSE, context.diffuse, ColorRGBA.White); - setMaterialColor(GL_SPECULAR, context.specular, ColorRGBA.Black); - - if (context.useVertexColor) { - glEnable(GL_COLOR_MATERIAL); - } else { - glDisable(GL_COLOR_MATERIAL); - } - } else { - // Ignore other values as they have no effect when - // GL_LIGHTING is disabled. - ColorRGBA color = context.color; - if (color != null) { - glColor4f(color.r, color.g, color.b, color.a); - } else { - glColor4f(1, 1, 1, 1); - } - } - if (context.alphaTestFallOff > 0f) { - glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GREATER, context.alphaTestFallOff); - } else { - glDisable(GL_ALPHA_TEST); - } - } - - /** - * Reset fixed function bindings to default values. - */ - private void resetFixedFuncBindings(){ - context.alphaTestFallOff = 0f; // zero means disable alpha test! - context.color = null; - context.ambient = null; - context.diffuse = null; - context.specular = null; - context.shininess = 0; - context.useVertexColor = false; - } - - public void setFixedFuncBinding(FixedFuncBinding ffBinding, Object val) { - switch (ffBinding) { - case Color: - context.color = (ColorRGBA) val; - break; - case MaterialAmbient: - context.ambient = (ColorRGBA) val; - break; - case MaterialDiffuse: - context.diffuse = (ColorRGBA) val; - break; - case MaterialSpecular: - context.specular = (ColorRGBA) val; - break; - case MaterialShininess: - context.shininess = (Float) val; - break; - case UseVertexColor: - context.useVertexColor = (Boolean) val; - break; - case AlphaTestFallOff: - context.alphaTestFallOff = (Float) val; - break; - } - } - - public void applyRenderState(RenderState state) { - if (state.isWireframe() && !context.wireframe) { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - context.wireframe = true; - } else if (!state.isWireframe() && context.wireframe) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - context.wireframe = false; - } - - if (state.isDepthTest() && !context.depthTestEnabled) { - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - context.depthTestEnabled = true; - } else if (!state.isDepthTest() && context.depthTestEnabled) { - glDisable(GL_DEPTH_TEST); - context.depthTestEnabled = false; - } - - if (state.isAlphaTest()) { - setFixedFuncBinding(FixedFuncBinding.AlphaTestFallOff, state.getAlphaFallOff()); - } else { - setFixedFuncBinding(FixedFuncBinding.AlphaTestFallOff, 0f); // disable it - } - - if (state.isDepthWrite() && !context.depthWriteEnabled) { - glDepthMask(true); - context.depthWriteEnabled = true; - } else if (!state.isDepthWrite() && context.depthWriteEnabled) { - glDepthMask(false); - context.depthWriteEnabled = false; - } - - if (state.isColorWrite() && !context.colorWriteEnabled) { - glColorMask(true, true, true, true); - context.colorWriteEnabled = true; - } else if (!state.isColorWrite() && context.colorWriteEnabled) { - glColorMask(false, false, false, false); - context.colorWriteEnabled = false; - } - - if (state.isPointSprite()) { - logger.log(Level.WARNING, "Point Sprite unsupported!"); - } - - if (state.isPolyOffset()) { - if (!context.polyOffsetEnabled) { - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(state.getPolyOffsetFactor(), - state.getPolyOffsetUnits()); - context.polyOffsetEnabled = true; - context.polyOffsetFactor = state.getPolyOffsetFactor(); - context.polyOffsetUnits = state.getPolyOffsetUnits(); - } else { - if (state.getPolyOffsetFactor() != context.polyOffsetFactor - || state.getPolyOffsetUnits() != context.polyOffsetUnits) { - glPolygonOffset(state.getPolyOffsetFactor(), - state.getPolyOffsetUnits()); - context.polyOffsetFactor = state.getPolyOffsetFactor(); - context.polyOffsetUnits = state.getPolyOffsetUnits(); - } - } - } else { - if (context.polyOffsetEnabled) { - glDisable(GL_POLYGON_OFFSET_FILL); - context.polyOffsetEnabled = false; - context.polyOffsetFactor = 0; - context.polyOffsetUnits = 0; - } - } - if (state.getFaceCullMode() != context.cullMode) { - if (state.getFaceCullMode() == RenderState.FaceCullMode.Off) { - glDisable(GL_CULL_FACE); - } else { - glEnable(GL_CULL_FACE); - } - - switch (state.getFaceCullMode()) { - case Off: - break; - case Back: - glCullFace(GL_BACK); - break; - case Front: - glCullFace(GL_FRONT); - break; - case FrontAndBack: - glCullFace(GL_FRONT_AND_BACK); - break; - default: - throw new UnsupportedOperationException("Unrecognized face cull mode: " - + state.getFaceCullMode()); - } - - context.cullMode = state.getFaceCullMode(); - } - - if (state.getBlendMode() != context.blendMode) { - if (state.getBlendMode() == RenderState.BlendMode.Off) { - glDisable(GL_BLEND); - } else { - glEnable(GL_BLEND); - switch (state.getBlendMode()) { - case Off: - break; - case Additive: - glBlendFunc(GL_ONE, GL_ONE); - break; - case AlphaAdditive: - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - break; - case Color: - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); - break; - case Alpha: - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - case PremultAlpha: - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - break; - case Modulate: - glBlendFunc(GL_DST_COLOR, GL_ZERO); - break; - case ModulateX2: - glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR); - break; - default: - throw new UnsupportedOperationException("Unrecognized blend mode: " - + state.getBlendMode()); - } - } - - context.blendMode = state.getBlendMode(); - } - - if (state.isStencilTest()) { - throw new UnsupportedOperationException("OpenGL 1.1 doesn't support two sided stencil operations."); - } - - } - - public void setViewPort(int x, int y, int w, int h) { - if (x != vpX || vpY != y || vpW != w || vpH != h) { - glViewport(x, y, w, h); - vpX = x; - vpY = y; - vpW = w; - vpH = h; - } - } - - public void setClipRect(int x, int y, int width, int height) { - if (!context.clipRectEnabled) { - glEnable(GL_SCISSOR_TEST); - context.clipRectEnabled = true; - } - if (clipX != x || clipY != y || clipW != width || clipH != height) { - glScissor(x, y, width, height); - clipX = x; - clipY = y; - clipW = width; - clipH = height; - } - } - - public void clearClipRect() { - if (context.clipRectEnabled) { - glDisable(GL_SCISSOR_TEST); - context.clipRectEnabled = false; - - clipX = 0; - clipY = 0; - clipW = 0; - clipH = 0; - } - } - - public void onFrame() { - objManager.deleteUnused(this); -// statistics.clearFrame(); - } - - private FloatBuffer storeMatrix(Matrix4f matrix, FloatBuffer store) { - store.clear(); - matrix.fillFloatBuffer(store, true); - store.clear(); - return store; - } - - private void setModelView(Matrix4f modelMatrix, Matrix4f viewMatrix){ - if (context.matrixMode != GL_MODELVIEW) { - glMatrixMode(GL_MODELVIEW); - context.matrixMode = GL_MODELVIEW; - } - - glLoadMatrix(storeMatrix(viewMatrix, fb16)); - glMultMatrix(storeMatrix(modelMatrix, fb16)); - } - - private void setProjection(Matrix4f projMatrix){ - if (context.matrixMode != GL_PROJECTION) { - glMatrixMode(GL_PROJECTION); - context.matrixMode = GL_PROJECTION; - } - - glLoadMatrix(storeMatrix(projMatrix, fb16)); - } - - public void setWorldMatrix(Matrix4f worldMatrix) { - this.worldMatrix.set(worldMatrix); - } - - public void setViewProjectionMatrices(Matrix4f viewMatrix, Matrix4f projMatrix) { - this.viewMatrix.set(viewMatrix); - setProjection(projMatrix); - } - - public void setLighting(LightList list) { - // XXX: This is abuse of setLighting() to - // apply fixed function bindings - // and do other book keeping. - if (list == null || list.size() == 0){ - glDisable(GL_LIGHTING); - applyFixedFuncBindings(false); - setModelView(worldMatrix, viewMatrix); - return; - } - - // Number of lights set previously - int numLightsSetPrev = lightList.size(); - - // If more than maxLights are defined, they will be ignored. - // The GL1 renderer is not permitted to crash due to a - // GL1 limitation. It must render anything that the GL2 renderer - // can render (even incorrectly). - lightList.clear(); - materialAmbientColor.set(0, 0, 0, 0); - - for (int i = 0; i < list.size(); i++){ - Light l = list.get(i); - if (l.getType() == Light.Type.Ambient){ - // Gather - materialAmbientColor.addLocal(l.getColor()); - }else{ - // Add to list - lightList.add(l); - - // Once maximum lights reached, exit loop. - if (lightList.size() >= maxLights){ - break; - } - } - } - - applyFixedFuncBindings(true); - - glEnable(GL_LIGHTING); - - fb16.clear(); - fb16.put(materialAmbientColor.r) - .put(materialAmbientColor.g) - .put(materialAmbientColor.b) - .put(1).flip(); - - glLightModel(GL_LIGHT_MODEL_AMBIENT, fb16); - - if (context.matrixMode != GL_MODELVIEW) { - glMatrixMode(GL_MODELVIEW); - context.matrixMode = GL_MODELVIEW; - } - // Lights are already in world space, so just convert - // them to view space. - glLoadMatrix(storeMatrix(viewMatrix, fb16)); - - for (int i = 0; i < lightList.size(); i++){ - int glLightIndex = GL_LIGHT0 + i; - Light light = lightList.get(i); - Light.Type lightType = light.getType(); - ColorRGBA col = light.getColor(); - Vector3f pos; - - // Enable the light - glEnable(glLightIndex); - - // OGL spec states default value for light ambient is black - switch (lightType){ - case Directional: - DirectionalLight dLight = (DirectionalLight) light; - - fb16.clear(); - fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip(); - glLight(glLightIndex, GL_DIFFUSE, fb16); - glLight(glLightIndex, GL_SPECULAR, fb16); - - pos = tempVec.set(dLight.getDirection()).negateLocal().normalizeLocal(); - fb16.clear(); - fb16.put(pos.x).put(pos.y).put(pos.z).put(0.0f).flip(); - glLight(glLightIndex, GL_POSITION, fb16); - glLightf(glLightIndex, GL_SPOT_CUTOFF, 180); - break; - case Point: - PointLight pLight = (PointLight) light; - - fb16.clear(); - fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip(); - glLight(glLightIndex, GL_DIFFUSE, fb16); - glLight(glLightIndex, GL_SPECULAR, fb16); - - pos = pLight.getPosition(); - fb16.clear(); - fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip(); - glLight(glLightIndex, GL_POSITION, fb16); - glLightf(glLightIndex, GL_SPOT_CUTOFF, 180); - - if (pLight.getRadius() > 0) { - // Note: this doesn't follow the same attenuation model - // as the one used in the lighting shader. - glLightf(glLightIndex, GL_CONSTANT_ATTENUATION, 1); - glLightf(glLightIndex, GL_LINEAR_ATTENUATION, pLight.getInvRadius() * 2); - glLightf(glLightIndex, GL_QUADRATIC_ATTENUATION, pLight.getInvRadius() * pLight.getInvRadius()); - }else{ - glLightf(glLightIndex, GL_CONSTANT_ATTENUATION, 1); - glLightf(glLightIndex, GL_LINEAR_ATTENUATION, 0); - glLightf(glLightIndex, GL_QUADRATIC_ATTENUATION, 0); - } - - break; - case Spot: - SpotLight sLight = (SpotLight) light; - - fb16.clear(); - fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip(); - glLight(glLightIndex, GL_DIFFUSE, fb16); - glLight(glLightIndex, GL_SPECULAR, fb16); - - pos = sLight.getPosition(); - fb16.clear(); - fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip(); - glLight(glLightIndex, GL_POSITION, fb16); - - Vector3f dir = sLight.getDirection(); - fb16.clear(); - fb16.put(dir.x).put(dir.y).put(dir.z).put(1.0f).flip(); - glLight(glLightIndex, GL_SPOT_DIRECTION, fb16); - - float outerAngleRad = sLight.getSpotOuterAngle(); - float innerAngleRad = sLight.getSpotInnerAngle(); - float spotCut = outerAngleRad * FastMath.RAD_TO_DEG; - float spotExpo = 0.0f; - if (outerAngleRad > 0) { - spotExpo = (1.0f - (innerAngleRad / outerAngleRad)) * 128.0f; - } - - glLightf(glLightIndex, GL_SPOT_CUTOFF, spotCut); - glLightf(glLightIndex, GL_SPOT_EXPONENT, spotExpo); - - if (sLight.getSpotRange() > 0) { - glLightf(glLightIndex, GL_LINEAR_ATTENUATION, sLight.getInvSpotRange()); - }else{ - glLightf(glLightIndex, GL_LINEAR_ATTENUATION, 0); - } - - break; - default: - throw new UnsupportedOperationException( - "Unrecognized light type: " + lightType); - } - } - - // Disable lights after the index - for (int i = lightList.size(); i < numLightsSetPrev; i++){ - glDisable(GL_LIGHT0 + i); - } - - // This will set view matrix as well. - setModelView(worldMatrix, viewMatrix); - } - - private int convertTextureType(Texture.Type type) { - switch (type) { - case TwoDimensional: - return GL_TEXTURE_2D; -// case ThreeDimensional: -// return GL_TEXTURE_3D; -// case CubeMap: -// return GL_TEXTURE_CUBE_MAP; - default: - throw new UnsupportedOperationException("Unknown texture type: " + type); - } - } - - private int convertMagFilter(Texture.MagFilter filter) { - switch (filter) { - case Bilinear: - return GL_LINEAR; - case Nearest: - return GL_NEAREST; - default: - throw new UnsupportedOperationException("Unknown mag filter: " + filter); - } - } - - private int convertMinFilter(Texture.MinFilter filter) { - switch (filter) { - case Trilinear: - return GL_LINEAR_MIPMAP_LINEAR; - case BilinearNearestMipMap: - return GL_LINEAR_MIPMAP_NEAREST; - case NearestLinearMipMap: - return GL_NEAREST_MIPMAP_LINEAR; - case NearestNearestMipMap: - return GL_NEAREST_MIPMAP_NEAREST; - case BilinearNoMipMaps: - return GL_LINEAR; - case NearestNoMipMaps: - return GL_NEAREST; - default: - throw new UnsupportedOperationException("Unknown min filter: " + filter); - } - } - - private int convertWrapMode(Texture.WrapMode mode) { - switch (mode) { - case EdgeClamp: - case Clamp: - case BorderClamp: - return GL_CLAMP; - case Repeat: - return GL_REPEAT; - default: - throw new UnsupportedOperationException("Unknown wrap mode: " + mode); - } - } - - private void setupTextureParams(Texture tex) { - int target = convertTextureType(tex.getType()); - - // filter things - int minFilter = convertMinFilter(tex.getMinFilter()); - int magFilter = convertMagFilter(tex.getMagFilter()); - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilter); - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilter); - - // repeat modes - switch (tex.getType()) { -// case ThreeDimensional: -// case CubeMap: -// glTexParameteri(target, GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R))); - case TwoDimensional: - glTexParameteri(target, GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T))); - // fall down here is intentional.. -// case OneDimensional: - glTexParameteri(target, GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S))); - break; - default: - throw new UnsupportedOperationException("Unknown texture type: " + tex.getType()); - } - } - - public void updateTexImageData(Image img, Texture.Type type, int unit) { - int texId = img.getId(); - if (texId == -1) { - // create texture - glGenTextures(ib1); - texId = ib1.get(0); - img.setId(texId); - objManager.registerObject(img); - - statistics.onNewTexture(); - } - - // bind texture - int target = convertTextureType(type); -// if (context.boundTextureUnit != unit) { -// glActiveTexture(GL_TEXTURE0 + unit); -// context.boundTextureUnit = unit; -// } - if (context.boundTextures[unit] != img) { - glEnable(target); - glBindTexture(target, texId); - context.boundTextures[unit] = img; - - statistics.onTextureUse(img, true); - } - - // Check sizes if graphics card doesn't support NPOT - if (!ctxCaps.GL_ARB_texture_non_power_of_two && img.isNPOT()) { - // Resize texture to Power-of-2 size - MipMapGenerator.resizeToPowerOf2(img); - } - - if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) { - // No pregenerated mips available, - // generate from base level if required - - // Check if hardware mips are supported - if (ctxCaps.OpenGL14) { - glTexParameteri(target, GL14.GL_GENERATE_MIPMAP, GL_TRUE); - } else { - MipMapGenerator.generateMipMaps(img); - } - img.setMipmapsGenerated(true); - } else { - } - - if (img.getWidth() > maxTexSize || img.getHeight() > maxTexSize) { - throw new RendererException("Cannot upload texture " + img + ". The maximum supported texture resolution is " + maxTexSize); - } - - /* - if (target == GL_TEXTURE_CUBE_MAP) { - List data = img.getData(); - if (data.size() != 6) { - logger.log(Level.WARNING, "Invalid texture: {0}\n" - + "Cubemap textures must contain 6 data units.", img); - return; - } - for (int i = 0; i < 6; i++) { - TextureUtil.uploadTexture(img, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, 0, tdc); - } - } else if (target == EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT) { - List data = img.getData(); - // -1 index specifies prepare data for 2D Array - TextureUtil.uploadTexture(img, target, -1, 0, tdc); - for (int i = 0; i < data.size(); i++) { - // upload each slice of 2D array in turn - // this time with the appropriate index - TextureUtil.uploadTexture(img, target, i, 0, tdc); - } - } else {*/ - TextureUtil.uploadTexture(caps, img, target, 0, 0, false); - //} - - img.clearUpdateNeeded(); - } - - public void setTexture(int unit, Texture tex) { - if (unit != 0 || tex.getType() != Texture.Type.TwoDimensional) { - //throw new UnsupportedOperationException(); - return; - } - - Image image = tex.getImage(); - if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated()) ) { - updateTexImageData(image, tex.getType(), unit); - } - - int texId = image.getId(); - assert texId != -1; - - Image[] textures = context.boundTextures; - - int type = convertTextureType(tex.getType()); -// if (!context.textureIndexList.moveToNew(unit)) { -// if (context.boundTextureUnit != unit){ -// glActiveTexture(GL_TEXTURE0 + unit); -// context.boundTextureUnit = unit; -// } -// glEnable(type); -// } - -// if (context.boundTextureUnit != unit) { -// glActiveTexture(GL_TEXTURE0 + unit); -// context.boundTextureUnit = unit; -// } - - if (textures[unit] != image) { - glEnable(type); - glBindTexture(type, texId); - textures[unit] = image; - - statistics.onTextureUse(image, true); - } else { - statistics.onTextureUse(image, false); - } - - setupTextureParams(tex); - } - - public void modifyTexture(Texture tex, Image pixels, int x, int y) { - setTexture(0, tex); - TextureUtil.uploadSubTexture(caps, pixels, convertTextureType(tex.getType()), 0, x, y, false); - } - - private void clearTextureUnits() { - Image[] textures = context.boundTextures; - if (textures[0] != null) { - glDisable(GL_TEXTURE_2D); - textures[0] = null; - } - } - - public void deleteImage(Image image) { - int texId = image.getId(); - if (texId != -1) { - ib1.put(0, texId); - ib1.position(0).limit(1); - glDeleteTextures(ib1); - image.resetObject(); - } - } - - private int convertArrayType(VertexBuffer.Type type) { - switch (type) { - case Position: - return GL_VERTEX_ARRAY; - case Normal: - return GL_NORMAL_ARRAY; - case TexCoord: - return GL_TEXTURE_COORD_ARRAY; - case Color: - return GL_COLOR_ARRAY; - default: - return -1; // unsupported - } - } - - private int convertVertexFormat(VertexBuffer.Format fmt) { - switch (fmt) { - case Byte: - return GL_BYTE; - case Float: - return GL_FLOAT; - case Int: - return GL_INT; - case Short: - return GL_SHORT; - case UnsignedByte: - return GL_UNSIGNED_BYTE; - case UnsignedInt: - return GL_UNSIGNED_INT; - case UnsignedShort: - return GL_UNSIGNED_SHORT; - default: - throw new UnsupportedOperationException("Unrecognized vertex format: " + fmt); - } - } - - private int convertElementMode(Mesh.Mode mode) { - switch (mode) { - case Points: - return GL_POINTS; - case Lines: - return GL_LINES; - case LineLoop: - return GL_LINE_LOOP; - case LineStrip: - return GL_LINE_STRIP; - case Triangles: - return GL_TRIANGLES; - case TriangleFan: - return GL_TRIANGLE_FAN; - case TriangleStrip: - return GL_TRIANGLE_STRIP; - default: - throw new UnsupportedOperationException("Unrecognized mesh mode: " + mode); - } - } - - public void drawTriangleArray(Mesh.Mode mode, int count, int vertCount) { - if (count > 1) { - throw new UnsupportedOperationException(); - } - - glDrawArrays(convertElementMode(mode), 0, vertCount); - } - - public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) { - if (vb.getBufferType() == VertexBuffer.Type.Color && !context.useVertexColor) { - // Ignore vertex color buffer if vertex color is disabled. - return; - } - - int arrayType = convertArrayType(vb.getBufferType()); - if (arrayType == -1) { - return; // unsupported - } - glEnableClientState(arrayType); - context.boundAttribs[vb.getBufferType().ordinal()] = vb; - - if (vb.getBufferType() == Type.Normal) { - // normalize if requested - if (vb.isNormalized() && !context.normalizeEnabled) { - glEnable(GL_NORMALIZE); - context.normalizeEnabled = true; - } else if (!vb.isNormalized() && context.normalizeEnabled) { - glDisable(GL_NORMALIZE); - context.normalizeEnabled = false; - } - } - - // NOTE: Use data from interleaved buffer if specified - Buffer data = idb != null ? idb.getData() : vb.getData(); - int comps = vb.getNumComponents(); - int type = convertVertexFormat(vb.getFormat()); - - data.rewind(); - - switch (vb.getBufferType()) { - case Position: - if (!(data instanceof FloatBuffer)) { - throw new UnsupportedOperationException(); - } - - glVertexPointer(comps, vb.getStride(), (FloatBuffer) data); - break; - case Normal: - if (!(data instanceof FloatBuffer)) { - throw new UnsupportedOperationException(); - } - - glNormalPointer(vb.getStride(), (FloatBuffer) data); - break; - case Color: - if (data instanceof FloatBuffer) { - glColorPointer(comps, vb.getStride(), (FloatBuffer) data); - } else if (data instanceof ByteBuffer) { - glColorPointer(comps, true, vb.getStride(), (ByteBuffer) data); - } else { - throw new UnsupportedOperationException(); - } - break; - case TexCoord: - if (!(data instanceof FloatBuffer)) { - throw new UnsupportedOperationException(); - } - - glTexCoordPointer(comps, vb.getStride(), (FloatBuffer) data); - break; - default: - // Ignore, this is an unsupported attribute for OpenGL1. - break; - } - } - - public void setVertexAttrib(VertexBuffer vb) { - setVertexAttrib(vb, null); - } - - private void drawElements(int mode, int format, Buffer data) { - switch (format) { - case GL_UNSIGNED_BYTE: - glDrawElements(mode, (ByteBuffer) data); - break; - case GL_UNSIGNED_SHORT: - glDrawElements(mode, (ShortBuffer) data); - break; - case GL_UNSIGNED_INT: - glDrawElements(mode, (IntBuffer) data); - break; - default: - throw new UnsupportedOperationException(); - } - } - - public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) { - Mesh.Mode mode = mesh.getMode(); - - Buffer indexData = indexBuf.getData(); - indexData.rewind(); - - if (mesh.getMode() == Mode.Hybrid) { - throw new UnsupportedOperationException(); - /* - int[] modeStart = mesh.getModeStart(); - int[] elementLengths = mesh.getElementLengths(); - - int elMode = convertElementMode(Mode.Triangles); - int fmt = convertVertexFormat(indexBuf.getFormat()); - // int elSize = indexBuf.getFormat().getComponentSize(); - // int listStart = modeStart[0]; - int stripStart = modeStart[1]; - int fanStart = modeStart[2]; - int curOffset = 0; - for (int i = 0; i < elementLengths.length; i++) { - if (i == stripStart) { - elMode = convertElementMode(Mode.TriangleStrip); - } else if (i == fanStart) { - elMode = convertElementMode(Mode.TriangleStrip); - } - int elementLength = elementLengths[i]; - indexData.position(curOffset); - - drawElements(elMode, - fmt, - indexData); - - curOffset += elementLength; - }*/ - } else { - drawElements(convertElementMode(mode), - convertVertexFormat(indexBuf.getFormat()), - indexData); - } - } - - public void clearVertexAttribs() { - for (int i = 0; i < 16; i++) { - VertexBuffer vb = context.boundAttribs[i]; - if (vb != null) { - int arrayType = convertArrayType(vb.getBufferType()); - glDisableClientState(arrayType); - context.boundAttribs[vb.getBufferType().ordinal()] = null; - } - } - } - - private void renderMeshDefault(Mesh mesh, int lod, int count) { - VertexBuffer indices; - - VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); - if (interleavedData != null && interleavedData.isUpdateNeeded()) { - updateBufferData(interleavedData); - } - - if (mesh.getNumLodLevels() > 0) { - indices = mesh.getLodLevel(lod); - } else { - indices = mesh.getBuffer(Type.Index); - } - for (VertexBuffer vb : mesh.getBufferList().getArray()) { - if (vb.getBufferType() == Type.InterleavedData - || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers - || vb.getBufferType() == Type.Index) { - continue; - } - - if (vb.getStride() == 0) { - // not interleaved - setVertexAttrib(vb); - } else { - // interleaved - setVertexAttrib(vb, interleavedData); - } - } - - if (indices != null) { - drawTriangleList(indices, mesh, count); - } else { - glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); - } - - // TODO: Fix these to use IDList?? - clearVertexAttribs(); - clearTextureUnits(); - resetFixedFuncBindings(); - } - - public void renderMesh(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) { - if (mesh.getVertexCount() == 0) { - return; - } - - if (context.pointSize != mesh.getPointSize()) { - glPointSize(mesh.getPointSize()); - context.pointSize = mesh.getPointSize(); - } - if (context.lineWidth != mesh.getLineWidth()) { - glLineWidth(mesh.getLineWidth()); - context.lineWidth = mesh.getLineWidth(); - } - - boolean dynamic = false; - if (mesh.getBuffer(Type.InterleavedData) != null) { - throw new UnsupportedOperationException("Interleaved meshes are not supported"); - } - - if (mesh.getNumLodLevels() == 0) { - for (VertexBuffer vb : mesh.getBufferList().getArray()) { - if (vb.getUsage() != VertexBuffer.Usage.Static) { - dynamic = true; - break; - } - } - } else { - dynamic = true; - } - - statistics.onMeshDrawn(mesh, lod); - -// if (!dynamic) { - // dealing with a static object, generate display list -// renderMeshDisplayList(mesh); -// } else { - renderMeshDefault(mesh, lod, count); -// } - - - } - - public void setAlphaToCoverage(boolean value) { - } - - public void setShader(Shader shader) { - } - - public void deleteShader(Shader shader) { - } - - public void deleteShaderSource(ShaderSource source) { - } - - public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst) { - } - - public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth) { - } - - public void setMainFrameBufferOverride(FrameBuffer fb){ - } - - public void setFrameBuffer(FrameBuffer fb) { - } - - public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) { - } - - public void deleteFrameBuffer(FrameBuffer fb) { - } - - public void updateBufferData(VertexBuffer vb) { - } - - public void deleteBuffer(VertexBuffer vb) { - } - - public void setMainFrameBufferSrgb(boolean srgb) { - - } - - public void setLinearizeSrgbImages(boolean linearize) { - - } -} diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java index 37640f3a5..ee6a29300 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java @@ -35,9 +35,8 @@ package com.jme3.system.lwjgl; import com.jme3.input.lwjgl.JInputJoyInput; import com.jme3.input.lwjgl.LwjglKeyInput; import com.jme3.input.lwjgl.LwjglMouseInput; -import com.jme3.math.FastMath; import com.jme3.renderer.Renderer; -import com.jme3.renderer.lwjgl.LwjglGL1Renderer; +import com.jme3.renderer.RendererException; import com.jme3.renderer.lwjgl.LwjglRenderer; import com.jme3.system.AppSettings; import com.jme3.system.JmeContext; @@ -199,30 +198,19 @@ public abstract class LwjglContext implements JmeContext { } protected void initContextFirstTime(){ + if (!GLContext.getCapabilities().OpenGL20) { + throw new RendererException("OpenGL 2.0 or higher is " + + "required for jMonkeyEngine"); + } + if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL2) - || settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)){ + || settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)) { renderer = new LwjglRenderer(); - }else if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL1)){ - renderer = new LwjglGL1Renderer(); - }else if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL_ANY)){ - // Choose an appropriate renderer based on capabilities - if (GLContext.getCapabilities().OpenGL20){ - renderer = new LwjglRenderer(); - }else{ - renderer = new LwjglGL1Renderer(); - } - }else{ + ((LwjglRenderer) renderer).initialize(); + } else { throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer()); } - // Init renderer - if (renderer instanceof LwjglRenderer){ - ((LwjglRenderer)renderer).initialize(); - }else if (renderer instanceof LwjglGL1Renderer){ - ((LwjglGL1Renderer)renderer).initialize(); - }else{ - assert false; - } renderer.setMainFrameBufferSrgb(settings.getGammaCorrection()); renderer.setLinearizeSrgbImages(settings.getGammaCorrection()); diff --git a/sdk/jme3-core/src/com/jme3/gde/core/editor/SceneApplication.java b/sdk/jme3-core/src/com/jme3/gde/core/editor/SceneApplication.java index a38a1b8bc..91d5238b9 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/editor/SceneApplication.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/editor/SceneApplication.java @@ -25,9 +25,6 @@ public class SceneApplication extends SimpleApplication { super(new StatsAppState()); AppSettings newSetting = new AppSettings(true); newSetting.setFrameRate(30); - if ("true".equals(NbPreferences.forModule(Installer.class).get("use_opengl_1", "false"))) { - newSetting.setRenderer(AppSettings.LWJGL_OPENGL1); - } newSetting.setCustomRenderer(AwtPanelsContext.class); setSettings(newSetting); setPauseOnLostFocus(false); diff --git a/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java b/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java index bf4d34335..00949fdeb 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java @@ -144,9 +144,6 @@ public class SceneApplication extends Application implements LookupProvider { try { AppSettings newSetting = new AppSettings(true); newSetting.setFrameRate(30); - if ("true".equals(NbPreferences.forModule(Installer.class).get("use_opengl_1", "false"))) { - newSetting.setRenderer(AppSettings.LWJGL_OPENGL1); - } if (!useCanvas) { newSetting.setCustomRenderer(AwtPanelsContext.class); }