Added a switch to use VECTORS on GLES and COMPONENTS/4 on Desktop

experimental
zzuegg 10 years ago
parent 4cd0c5bffb
commit 8cb2be60fe
  1. 87
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java

@ -56,6 +56,7 @@ import com.jme3.util.BufferUtils;
import com.jme3.util.ListMap; import com.jme3.util.ListMap;
import com.jme3.util.MipMapGenerator; import com.jme3.util.MipMapGenerator;
import com.jme3.util.NativeObjectManager; import com.jme3.util.NativeObjectManager;
import java.nio.*; import java.nio.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.EnumMap; import java.util.EnumMap;
@ -66,6 +67,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import jme3tools.shader.ShaderDebug; import jme3tools.shader.ShaderDebug;
public class GLRenderer implements Renderer { public class GLRenderer implements Renderer {
@ -101,9 +103,9 @@ public class GLRenderer implements Renderer {
public GLRenderer(GL gl, GLExt glext, GLFbo glfbo) { public GLRenderer(GL gl, GLExt glext, GLFbo glfbo) {
this.gl = gl; this.gl = gl;
this.gl2 = gl instanceof GL2 ? (GL2)gl : null; this.gl2 = gl instanceof GL2 ? (GL2) gl : null;
this.gl3 = gl instanceof GL3 ? (GL3)gl : null; this.gl3 = gl instanceof GL3 ? (GL3) gl : null;
this.gl4 = gl instanceof GL4 ? (GL4)gl : null; this.gl4 = gl instanceof GL4 ? (GL4) gl : null;
this.glfbo = glfbo; this.glfbo = glfbo;
this.glext = glext; this.glext = glext;
this.texUtil = new TextureUtil(gl, gl2, glext, context); this.texUtil = new TextureUtil(gl, gl2, glext, context);
@ -257,7 +259,11 @@ public class GLRenderer implements Renderer {
// gl.glGetInteger(GL.GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, intBuf16); // gl.glGetInteger(GL.GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, intBuf16);
// fragUniforms = intBuf16.get(0); // fragUniforms = intBuf16.get(0);
// logger.log(Level.FINER, "Fragment Uniforms: {0}", fragUniforms); // logger.log(Level.FINER, "Fragment Uniforms: {0}", fragUniforms);
limits.put(Limits.VertexUniformComponents,getInteger(GL.GL_MAX_VERTEX_UNIFORM_COMPONENTS)); if (caps.contains(Caps.OpenGLES20)) {
limits.put(Limits.VertexUniformVectors, getInteger(GL.GL_MAX_VERTEX_UNIFORM_VECTORS));
} else {
limits.put(Limits.VertexUniformVectors, getInteger(GL.GL_MAX_VERTEX_UNIFORM_COMPONENTS) / 4);
}
limits.put(Limits.VertexAttributes, getInteger(GL.GL_MAX_VERTEX_ATTRIBS)); limits.put(Limits.VertexAttributes, getInteger(GL.GL_MAX_VERTEX_ATTRIBS));
limits.put(Limits.TextureSize, getInteger(GL.GL_MAX_TEXTURE_SIZE)); limits.put(Limits.TextureSize, getInteger(GL.GL_MAX_TEXTURE_SIZE));
limits.put(Limits.CubemapSize, getInteger(GL.GL_MAX_CUBE_MAP_TEXTURE_SIZE)); limits.put(Limits.CubemapSize, getInteger(GL.GL_MAX_CUBE_MAP_TEXTURE_SIZE));
@ -421,8 +427,8 @@ public class GLRenderer implements Renderer {
} }
// Supports sRGB pipeline. // Supports sRGB pipeline.
if ( (hasExtension("GL_ARB_framebuffer_sRGB") && hasExtension("GL_EXT_texture_sRGB")) if ((hasExtension("GL_ARB_framebuffer_sRGB") && hasExtension("GL_EXT_texture_sRGB"))
|| caps.contains(Caps.OpenGL30) ) { || caps.contains(Caps.OpenGL30)) {
caps.add(Caps.Srgb); caps.add(Caps.Srgb);
} }
@ -461,8 +467,7 @@ public class GLRenderer implements Renderer {
if (logger.isLoggable(Level.FINE)) { if (logger.isLoggable(Level.FINE)) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Supported capabilities: \n"); sb.append("Supported capabilities: \n");
for (Caps cap : caps) for (Caps cap : caps) {
{
sb.append("\t").append(cap.toString()).append("\n"); sb.append("\t").append(cap.toString()).append("\n");
} }
logger.log(Level.FINE, sb.toString()); logger.log(Level.FINE, sb.toString());
@ -488,7 +493,7 @@ public class GLRenderer implements Renderer {
private boolean getBoolean(int en) { private boolean getBoolean(int en) {
gl.glGetBoolean(en, nameBuf); gl.glGetBoolean(en, nameBuf);
return nameBuf.get(0) != (byte)0; return nameBuf.get(0) != (byte) 0;
} }
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
@ -535,9 +540,11 @@ public class GLRenderer implements Renderer {
invalidateState(); invalidateState();
} }
/*********************************************************************\ /**
|* Render State *| * ******************************************************************\
\*********************************************************************/ * |* Render State *|
* \********************************************************************
*/
public void setDepthRange(float start, float end) { public void setDepthRange(float start, float end) {
gl.glDepthRange(start, end); gl.glDepthRange(start, end);
} }
@ -814,9 +821,11 @@ public class GLRenderer implements Renderer {
} }
} }
/*********************************************************************\ /**
|* Camera and World transforms *| * ******************************************************************\
\*********************************************************************/ * |* Camera and World transforms *|
* \********************************************************************
*/
public void setViewPort(int x, int y, int w, int h) { public void setViewPort(int x, int y, int w, int h) {
if (x != vpX || vpY != y || vpW != w || vpH != h) { if (x != vpX || vpY != y || vpW != w || vpH != h) {
gl.glViewport(x, y, w, h); gl.glViewport(x, y, w, h);
@ -858,9 +867,11 @@ public class GLRenderer implements Renderer {
gl.resetStats(); gl.resetStats();
} }
/*********************************************************************\ /**
|* Shaders *| * ******************************************************************\
\*********************************************************************/ * |* Shaders *|
* \********************************************************************
*/
protected void updateUniformLocation(Shader shader, Uniform uniform) { protected void updateUniformLocation(Shader shader, Uniform uniform) {
int loc = gl.glGetUniformLocation(shader.getId(), uniform.getName()); int loc = gl.glGetUniformLocation(shader.getId(), uniform.getName());
if (loc < 0) { if (loc < 0) {
@ -1082,7 +1093,7 @@ public class GLRenderer implements Renderer {
intBuf1.clear(); intBuf1.clear();
intBuf1.put(0, stringBuf.length()); intBuf1.put(0, stringBuf.length());
gl.glShaderSource(id, new String[]{ stringBuf.toString() }, intBuf1); gl.glShaderSource(id, new String[]{stringBuf.toString()}, intBuf1);
gl.glCompileShader(id); gl.glCompileShader(id);
gl.glGetShader(id, GL.GL_COMPILE_STATUS, intBuf1); gl.glGetShader(id, GL.GL_COMPILE_STATUS, intBuf1);
@ -1245,9 +1256,11 @@ public class GLRenderer implements Renderer {
shader.resetObject(); shader.resetObject();
} }
/*********************************************************************\ /**
|* Framebuffers *| * ******************************************************************\
\*********************************************************************/ * |* Framebuffers *|
* \********************************************************************
*/
public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst) { public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst) {
copyFrameBuffer(src, dst, true); copyFrameBuffer(src, dst, true);
} }
@ -1695,9 +1708,11 @@ public class GLRenderer implements Renderer {
} }
} }
/*********************************************************************\ /**
|* Textures *| * ******************************************************************\
\*********************************************************************/ * |* Textures *|
* \********************************************************************
*/
private int convertTextureType(Texture.Type type, int samples, int face) { private int convertTextureType(Texture.Type type, int samples, int face) {
if (samples > 1 && !caps.contains(Caps.TextureMultisample)) { if (samples > 1 && !caps.contains(Caps.TextureMultisample)) {
throw new RendererException("Multisample textures are not supported" + throw new RendererException("Multisample textures are not supported" +
@ -1752,7 +1767,7 @@ public class GLRenderer implements Renderer {
} }
private int convertMinFilter(Texture.MinFilter filter, boolean haveMips) { private int convertMinFilter(Texture.MinFilter filter, boolean haveMips) {
if (haveMips){ if (haveMips) {
switch (filter) { switch (filter) {
case Trilinear: case Trilinear:
return GL.GL_LINEAR_MIPMAP_LINEAR; return GL.GL_LINEAR_MIPMAP_LINEAR;
@ -1867,7 +1882,7 @@ public class GLRenderer implements Renderer {
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType()); throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
} }
if(tex.isNeedCompareModeUpdate() && gl2 != null){ if (tex.isNeedCompareModeUpdate() && gl2 != null) {
// R to Texture compare mode // R to Texture compare mode
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) { if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE); gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE);
@ -1877,7 +1892,7 @@ public class GLRenderer implements Renderer {
} else { } else {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL); gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
} }
}else{ } else {
//restoring default value //restoring default value
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE); gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
} }
@ -2146,9 +2161,11 @@ public class GLRenderer implements Renderer {
} }
} }
/*********************************************************************\ /**
|* Vertex Buffers and Attributes *| * ******************************************************************\
\*********************************************************************/ * |* Vertex Buffers and Attributes *|
* \********************************************************************
*/
private int convertUsage(Usage usage) { private int convertUsage(Usage usage) {
switch (usage) { switch (usage) {
case Static: case Static:
@ -2486,9 +2503,11 @@ public class GLRenderer implements Renderer {
} }
} }
/*********************************************************************\ /**
|* Render Calls *| * ******************************************************************\
\*********************************************************************/ * |* Render Calls *|
* \********************************************************************
*/
public int convertElementMode(Mesh.Mode mode) { public int convertElementMode(Mesh.Mode mode) {
switch (mode) { switch (mode) {
case Points: case Points:

Loading…
Cancel
Save