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

experimental
zzuegg 10 years ago
parent 4cd0c5bffb
commit 8cb2be60fe
  1. 169
      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.MipMapGenerator;
import com.jme3.util.NativeObjectManager;
import java.nio.*;
import java.util.Arrays;
import java.util.EnumMap;
@ -66,6 +67,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jme3tools.shader.ShaderDebug;
public class GLRenderer implements Renderer {
@ -101,9 +103,9 @@ public class GLRenderer implements Renderer {
public GLRenderer(GL gl, GLExt glext, GLFbo glfbo) {
this.gl = gl;
this.gl2 = gl instanceof GL2 ? (GL2)gl : null;
this.gl3 = gl instanceof GL3 ? (GL3)gl : null;
this.gl4 = gl instanceof GL4 ? (GL4)gl : null;
this.gl2 = gl instanceof GL2 ? (GL2) gl : null;
this.gl3 = gl instanceof GL3 ? (GL3) gl : null;
this.gl4 = gl instanceof GL4 ? (GL4) gl : null;
this.glfbo = glfbo;
this.glext = glext;
this.texUtil = new TextureUtil(gl, gl2, glext, context);
@ -257,13 +259,17 @@ public class GLRenderer implements Renderer {
// gl.glGetInteger(GL.GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, intBuf16);
// fragUniforms = intBuf16.get(0);
// 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.TextureSize, getInteger(GL.GL_MAX_TEXTURE_SIZE));
limits.put(Limits.CubemapSize, getInteger(GL.GL_MAX_CUBE_MAP_TEXTURE_SIZE));
if (hasExtension("GL_ARB_draw_instanced") &&
hasExtension("GL_ARB_instanced_arrays")) {
hasExtension("GL_ARB_instanced_arrays")) {
caps.add(Caps.MeshInstancing);
}
@ -280,11 +286,11 @@ public class GLRenderer implements Renderer {
boolean hasFloatTexture;
hasFloatTexture = hasExtension("GL_OES_texture_half_float") &&
hasExtension("GL_OES_texture_float");
hasExtension("GL_OES_texture_float");
if (!hasFloatTexture) {
hasFloatTexture = hasExtension("GL_ARB_texture_float") &&
hasExtension("GL_ARB_half_float_pixel");
hasExtension("GL_ARB_half_float_pixel");
if (!hasFloatTexture) {
hasFloatTexture = caps.contains(Caps.OpenGL30);
@ -302,8 +308,8 @@ public class GLRenderer implements Renderer {
}
if (hasExtension("GL_OES_rgb8_rgba8") ||
hasExtension("GL_ARM_rgba8") ||
hasExtension("GL_EXT_texture_format_BGRA8888")) {
hasExtension("GL_ARM_rgba8") ||
hasExtension("GL_EXT_texture_format_BGRA8888")) {
caps.add(Caps.Rgba8);
}
@ -312,7 +318,7 @@ public class GLRenderer implements Renderer {
}
if (hasExtension("GL_ARB_color_buffer_float") &&
hasExtension("GL_ARB_half_float_pixel")) {
hasExtension("GL_ARB_half_float_pixel")) {
// XXX: Require both 16 and 32 bit float support for FloatColorBuffer.
caps.add(Caps.FloatColorBuffer);
}
@ -322,7 +328,7 @@ public class GLRenderer implements Renderer {
}
if ((hasExtension("GL_EXT_packed_float") && hasFloatTexture) ||
caps.contains(Caps.OpenGL30)) {
caps.contains(Caps.OpenGL30)) {
// Either OpenGL3 is available or both packed_float & half_float_pixel.
caps.add(Caps.PackedFloatColorBuffer);
caps.add(Caps.PackedFloatTexture);
@ -350,13 +356,13 @@ public class GLRenderer implements Renderer {
}
if (hasExtension("GL_ARB_texture_non_power_of_two") ||
hasExtension("GL_OES_texture_npot") ||
caps.contains(Caps.OpenGL30)) {
hasExtension("GL_OES_texture_npot") ||
caps.contains(Caps.OpenGL30)) {
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.");
+ "support non-power-of-2 textures. "
+ "Some features might not work.");
}
if (caps.contains(Caps.OpenGLES20)) {
@ -421,8 +427,8 @@ public class GLRenderer implements Renderer {
}
// Supports sRGB pipeline.
if ( (hasExtension("GL_ARB_framebuffer_sRGB") && hasExtension("GL_EXT_texture_sRGB"))
|| caps.contains(Caps.OpenGL30) ) {
if ((hasExtension("GL_ARB_framebuffer_sRGB") && hasExtension("GL_EXT_texture_sRGB"))
|| caps.contains(Caps.OpenGL30)) {
caps.add(Caps.Srgb);
}
@ -444,25 +450,24 @@ public class GLRenderer implements Renderer {
// Print context information
logger.log(Level.INFO, "OpenGL Renderer Information\n" +
" * Vendor: {0}\n" +
" * Renderer: {1}\n" +
" * OpenGL Version: {2}\n" +
" * GLSL Version: {3}\n" +
" * Profile: {4}",
new Object[]{
gl.glGetString(GL.GL_VENDOR),
gl.glGetString(GL.GL_RENDERER),
gl.glGetString(GL.GL_VERSION),
gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION),
caps.contains(Caps.CoreProfile) ? "Core" : "Compatibility"
});
" * Vendor: {0}\n" +
" * Renderer: {1}\n" +
" * OpenGL Version: {2}\n" +
" * GLSL Version: {3}\n" +
" * Profile: {4}",
new Object[]{
gl.glGetString(GL.GL_VENDOR),
gl.glGetString(GL.GL_RENDERER),
gl.glGetString(GL.GL_VERSION),
gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION),
caps.contains(Caps.CoreProfile) ? "Core" : "Compatibility"
});
// Print capabilities (if fine logging is enabled)
if (logger.isLoggable(Level.FINE)) {
StringBuilder sb = new StringBuilder();
sb.append("Supported capabilities: \n");
for (Caps cap : caps)
{
for (Caps cap : caps) {
sb.append("\t").append(cap.toString()).append("\n");
}
logger.log(Level.FINE, sb.toString());
@ -488,7 +493,7 @@ public class GLRenderer implements Renderer {
private boolean getBoolean(int en) {
gl.glGetBoolean(en, nameBuf);
return nameBuf.get(0) != (byte)0;
return nameBuf.get(0) != (byte) 0;
}
@SuppressWarnings("fallthrough")
@ -535,9 +540,11 @@ public class GLRenderer implements Renderer {
invalidateState();
}
/*********************************************************************\
|* Render State *|
\*********************************************************************/
/**
* ******************************************************************\
* |* Render State *|
* \********************************************************************
*/
public void setDepthRange(float start, float 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) {
if (x != vpX || vpY != y || vpW != w || vpH != h) {
gl.glViewport(x, y, w, h);
@ -858,9 +867,11 @@ public class GLRenderer implements Renderer {
gl.resetStats();
}
/*********************************************************************\
|* Shaders *|
\*********************************************************************/
/**
* ******************************************************************\
* |* Shaders *|
* \********************************************************************
*/
protected void updateUniformLocation(Shader shader, Uniform uniform) {
int loc = gl.glGetUniformLocation(shader.getId(), uniform.getName());
if (loc < 0) {
@ -1043,7 +1054,7 @@ public class GLRenderer implements Renderer {
if (gles2 && !language.equals("GLSL100")) {
throw new RendererException("This shader cannot run in OpenGL ES 2. "
+ "Only GLSL 1.00 shaders are supported.");
+ "Only GLSL 1.00 shaders are supported.");
}
// Upload shader source.
@ -1082,7 +1093,7 @@ public class GLRenderer implements Renderer {
intBuf1.clear();
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.glGetShader(id, GL.GL_COMPILE_STATUS, intBuf1);
@ -1245,9 +1256,11 @@ public class GLRenderer implements Renderer {
shader.resetObject();
}
/*********************************************************************\
|* Framebuffers *|
\*********************************************************************/
/**
* ******************************************************************\
* |* Framebuffers *|
* \********************************************************************
*/
public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst) {
copyFrameBuffer(src, dst, true);
}
@ -1663,7 +1676,7 @@ public class GLRenderer implements Renderer {
gl.glReadPixels(vpX, vpY, vpW, vpH, glFormat, dataType, byteBuf);
}
public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) {
public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) {
GLImageFormat glFormat = texUtil.getImageFormatWithError(format, false);
readFrameBufferWithGLFormat(fb, byteBuf, glFormat.format, glFormat.dataType);
}
@ -1695,13 +1708,15 @@ public class GLRenderer implements Renderer {
}
}
/*********************************************************************\
|* Textures *|
\*********************************************************************/
/**
* ******************************************************************\
* |* Textures *|
* \********************************************************************
*/
private int convertTextureType(Texture.Type type, int samples, int face) {
if (samples > 1 && !caps.contains(Caps.TextureMultisample)) {
throw new RendererException("Multisample textures are not supported" +
" by the video hardware.");
" by the video hardware.");
}
switch (type) {
@ -1724,7 +1739,7 @@ public class GLRenderer implements Renderer {
case ThreeDimensional:
if (!caps.contains(Caps.OpenGL20)) {
throw new RendererException("3D textures are not supported" +
" by the video hardware.");
" by the video hardware.");
}
return GL2.GL_TEXTURE_3D;
case CubeMap:
@ -1752,7 +1767,7 @@ public class GLRenderer implements Renderer {
}
private int convertMinFilter(Texture.MinFilter filter, boolean haveMips) {
if (haveMips){
if (haveMips) {
switch (filter) {
case Trilinear:
return GL.GL_LINEAR_MIPMAP_LINEAR;
@ -1867,7 +1882,7 @@ public class GLRenderer implements Renderer {
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
}
if(tex.isNeedCompareModeUpdate() && gl2 != null){
if (tex.isNeedCompareModeUpdate() && gl2 != null) {
// R to Texture compare mode
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE);
@ -1877,9 +1892,9 @@ public class GLRenderer implements Renderer {
} else {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
}
}else{
//restoring default value
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
} else {
//restoring default value
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
}
tex.compareModeUpdated();
}
@ -1910,13 +1925,13 @@ public class GLRenderer implements Renderer {
if (!caps.contains(Caps.PartialNonPowerOfTwoTextures)) {
// Cannot use any type of NPOT texture (uncommon)
throw new RendererException("non-power-of-2 textures are not "
+ "supported by the video hardware");
+ "supported by the video hardware");
}
// Partial NPOT supported..
if (tex.getMinFilter().usesMipMapLevels()) {
throw new RendererException("non-power-of-2 textures with mip-maps "
+ "are not supported by the video hardware");
+ "are not supported by the video hardware");
}
switch (tex.getType()) {
@ -1924,7 +1939,7 @@ public class GLRenderer implements Renderer {
case ThreeDimensional:
if (tex.getWrap(WrapAxis.R) != Texture.WrapMode.EdgeClamp) {
throw new RendererException("repeating non-power-of-2 textures "
+ "are not supported by the video hardware");
+ "are not supported by the video hardware");
}
// fallthrough intentional!!!
case TwoDimensionalArray:
@ -1932,7 +1947,7 @@ public class GLRenderer implements Renderer {
if (tex.getWrap(WrapAxis.S) != Texture.WrapMode.EdgeClamp
|| tex.getWrap(WrapAxis.T) != Texture.WrapMode.EdgeClamp) {
throw new RendererException("repeating non-power-of-2 textures "
+ "are not supported by the video hardware");
+ "are not supported by the video hardware");
}
break;
default:
@ -1943,11 +1958,11 @@ public class GLRenderer implements Renderer {
/**
* Uploads the given image to the GL driver.
*
* @param img The image to upload
* @param type How the data in the image argument should be interpreted.
* @param unit The texture slot to be used to upload the image, not important
* @param img The image to upload
* @param type How the data in the image argument should be interpreted.
* @param unit The texture slot to be used to upload the image, not important
* @param scaleToPot If true, the image will be scaled to power-of-2 dimensions
* before being uploaded.
* before being uploaded.
*/
public void updateTexImageData(Image img, Texture.Type type, int unit, boolean scaleToPot) {
int texId = img.getId();
@ -2095,9 +2110,9 @@ public class GLRenderer implements Renderer {
int nextWidth = FastMath.nearestPowerOfTwo(tex.getImage().getWidth());
int nextHeight = FastMath.nearestPowerOfTwo(tex.getImage().getHeight());
logger.log(Level.WARNING,
"Non-power-of-2 textures are not supported! Scaling texture '" + tex.getName() +
"' of size " + tex.getImage().getWidth() + "x" + tex.getImage().getHeight() +
" to " + nextWidth + "x" + nextHeight);
"Non-power-of-2 textures are not supported! Scaling texture '" + tex.getName() +
"' of size " + tex.getImage().getWidth() + "x" + tex.getImage().getHeight() +
" to " + nextWidth + "x" + nextHeight);
}
scaleToPot = true;
}
@ -2146,9 +2161,11 @@ public class GLRenderer implements Renderer {
}
}
/*********************************************************************\
|* Vertex Buffers and Attributes *|
\*********************************************************************/
/**
* ******************************************************************\
* |* Vertex Buffers and Attributes *|
* \********************************************************************
*/
private int convertUsage(Usage usage) {
switch (usage) {
case Static:
@ -2486,9 +2503,11 @@ public class GLRenderer implements Renderer {
}
}
/*********************************************************************\
|* Render Calls *|
\*********************************************************************/
/**
* ******************************************************************\
* |* Render Calls *|
* \********************************************************************
*/
public int convertElementMode(Mesh.Mode mode) {
switch (mode) {
case Points:
@ -2654,7 +2673,7 @@ public class GLRenderer implements Renderer {
if (!caps.contains(Caps.Srgb) && enableSrgb) {
// Not supported, sorry.
logger.warning("sRGB framebuffer is not supported " +
"by video hardware, but was requested.");
"by video hardware, but was requested.");
return;
}

Loading…
Cancel
Save