Uses almost the same initialization sequence than the shader-based renderer relying on its competitor

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9884 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
jul..om 12 years ago
parent 25351e3fae
commit c84efe3436
  1. 622
      engine/src/jogl/com/jme3/renderer/jogl/JoglRenderer.java

@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jme3.renderer.jogl; package com.jme3.renderer.jogl;
import com.jme3.light.LightList; import com.jme3.light.LightList;
@ -81,154 +80,147 @@ import jme3tools.converters.MipMapGenerator;
public class JoglRenderer implements Renderer { public class JoglRenderer implements Renderer {
private static final Logger logger = Logger.getLogger(JoglRenderer.class.getName()); private static final Logger logger = Logger.getLogger(JoglRenderer.class.getName());
private static final boolean VALIDATE_SHADER = false;
protected Statistics statistics = new Statistics(); private final ByteBuffer nameBuf = BufferUtils.createByteBuffer(250);
private final StringBuilder stringBuf = new StringBuilder(250);
protected Matrix4f worldMatrix = new Matrix4f();
protected Matrix4f viewMatrix = new Matrix4f();
protected Matrix4f projMatrix = new Matrix4f();
protected FloatBuffer fb16 = BufferUtils.createFloatBuffer(16);
private final IntBuffer intBuf1 = BufferUtils.createIntBuffer(1); private final IntBuffer intBuf1 = BufferUtils.createIntBuffer(1);
private final IntBuffer intBuf16 = BufferUtils.createIntBuffer(16); private final IntBuffer intBuf16 = BufferUtils.createIntBuffer(16);
private RenderContext context = new RenderContext(); private RenderContext context = new RenderContext();
private NativeObjectManager objManager = new NativeObjectManager(); private NativeObjectManager objManager = new NativeObjectManager();
private EnumSet<Caps> caps = EnumSet.noneOf(Caps.class); private EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
//current state
private Shader boundShader; private Shader boundShader;
private int initialDrawBuf, initialReadBuf; private int initialDrawBuf, initialReadBuf;
private int glslVer; private int glslVer;
private int vertexTextureUnits; private int vertexTextureUnits;
private int fragTextureUnits; private int fragTextureUnits;
private int vertexUniforms; private int vertexUniforms;
private int fragUniforms; private int fragUniforms;
private int vertexAttribs; private int vertexAttribs;
private int maxFBOSamples; private int maxFBOSamples;
private int maxFBOAttachs; private int maxFBOAttachs;
private int maxMRTFBOAttachs; private int maxMRTFBOAttachs;
private int maxRBSize; private int maxRBSize;
private int maxTexSize; private int maxTexSize;
private int maxCubeTexSize; private int maxCubeTexSize;
private int maxVertCount; private int maxVertCount;
private int maxTriCount; private int maxTriCount;
private int maxColorTexSamples; private int maxColorTexSamples;
private int maxDepthTexSamples; private int maxDepthTexSamples;
private boolean tdc;
private boolean powerOf2 = false;
private boolean hardwareMips = false;
private boolean vbo = false;
private int vpX, vpY, vpW, vpH;
private FrameBuffer lastFb = null; private FrameBuffer lastFb = null;
private FrameBuffer mainFbOverride = null; private FrameBuffer mainFbOverride = null;
private final Statistics statistics = new Statistics();
private int vpX, vpY, vpW, vpH;
private int clipX, clipY, clipW, clipH;
//TODO: remove?
protected Matrix4f worldMatrix = new Matrix4f();
protected Matrix4f viewMatrix = new Matrix4f();
protected Matrix4f projMatrix = new Matrix4f();
protected FloatBuffer fb16 = BufferUtils.createFloatBuffer(16);
public JoglRenderer() { public JoglRenderer() {
} }
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() { public Statistics getStatistics() {
return statistics; return statistics;
} }
public void initialize() { public void initialize() {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
logger.log(Level.INFO, "Vendor: {0}", gl.glGetString(GL.GL_VENDOR)); //logger.log(Level.INFO, "Vendor: {0}", gl.glGetString(GL.GL_VENDOR));
logger.log(Level.INFO, "Renderer: {0}", gl.glGetString(GL.GL_RENDERER)); //logger.log(Level.INFO, "Renderer: {0}", gl.glGetString(GL.GL_RENDERER));
logger.log(Level.INFO, "Version: {0}", gl.glGetString(GL.GL_VERSION)); //logger.log(Level.INFO, "Version: {0}", gl.glGetString(GL.GL_VERSION));
applyRenderState(RenderState.DEFAULT);
powerOf2 = true/*gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two")*/;
hardwareMips = true/*gl.isExtensionAvailable("GL_SGIS_generate_mipmap")*/;
vbo = true/*gl.isExtensionAvailable("GL_ARB_vertex_buffer_object")*/;
if (gl.isExtensionAvailable("GL_VERSION_2_0")) { if (gl.isExtensionAvailable("GL_VERSION_2_0")) {
caps.add(Caps.OpenGL20); caps.add(Caps.OpenGL20);
} if (gl.isExtensionAvailable("GL_VERSION_2_1")) {
if (gl.isExtensionAvailable("GL_VERSION_2_1")) { caps.add(Caps.OpenGL21);
caps.add(Caps.OpenGL21); if (gl.isExtensionAvailable("GL_VERSION_3_0")) {
} caps.add(Caps.OpenGL30);
if (gl.isExtensionAvailable("GL_VERSION_3_0")) { if (gl.isExtensionAvailable("GL_VERSION_3_1")) {
caps.add(Caps.OpenGL30); caps.add(Caps.OpenGL31);
if (gl.isExtensionAvailable("GL_VERSION_3_2")) {
caps.add(Caps.OpenGL32);
}
}
}
}
} }
String versionStr = gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION); String versionStr = null;
if (caps.contains(Caps.OpenGL20)) {
versionStr = gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION);
}
if (versionStr == null || versionStr.equals("")) { if (versionStr == null || versionStr.equals("")) {
glslVer = -1; glslVer = -1;
// no, I need the support of low end graphics cards too throw new UnsupportedOperationException("GLSL and OpenGL2 is " +
/*throw new UnsupportedOperationException("GLSL and OpenGL2 is " + "required for the JOGL " +
"required for the JOGL " + "renderer!");
"renderer!");*/
}
else {
int spaceIdx = versionStr.indexOf(" ");
if (spaceIdx >= 1) {
versionStr = versionStr.substring(0, spaceIdx);
}
float version = Float.parseFloat(versionStr);
glslVer = (int) (version * 100);
switch (glslVer) {
default:
if (glslVer < 400) {
break;
}
// so that future OpenGL revisions wont break jme3
// fall through intentional
case 400:
case 330:
case 150:
caps.add(Caps.GLSL150);
case 140:
caps.add(Caps.GLSL140);
case 130:
caps.add(Caps.GLSL130);
case 120:
caps.add(Caps.GLSL120);
case 110:
caps.add(Caps.GLSL110);
case 100:
caps.add(Caps.GLSL100);
break;
}
// N.B: do NOT force GLSL100 support
} }
// Fix issue in TestRenderToMemory when GL_FRONT is the main
// buffer being used.
gl.glGetIntegerv(GL2GL3.GL_DRAW_BUFFER, intBuf1); gl.glGetIntegerv(GL2GL3.GL_DRAW_BUFFER, intBuf1);
initialDrawBuf = intBuf1.get(0); initialDrawBuf = intBuf1.get(0);
gl.glGetIntegerv(GL2GL3.GL_READ_BUFFER, intBuf1); gl.glGetIntegerv(GL2GL3.GL_READ_BUFFER, intBuf1);
initialReadBuf = intBuf1.get(0); initialReadBuf = intBuf1.get(0);
// XXX: This has to be GL_BACK for canvas on Mac
// Since initialDrawBuf is GL_FRONT for pbuffer, gotta
// change this value later on ...
// initialDrawBuf = GL_BACK;
// initialReadBuf = GL_BACK;
int spaceIdx = versionStr.indexOf(" ");
if (spaceIdx >= 1) {
versionStr = versionStr.substring(0, spaceIdx);
}
float version = Float.parseFloat(versionStr);
glslVer = (int) (version * 100);
switch (glslVer) {
default:
if (glslVer < 400) {
break;
}
// so that future OpenGL revisions wont break jme3
// fall through intentional
case 400:
case 330:
case 150:
caps.add(Caps.GLSL150);
case 140:
caps.add(Caps.GLSL140);
case 130:
caps.add(Caps.GLSL130);
case 120:
caps.add(Caps.GLSL120);
case 110:
caps.add(Caps.GLSL110);
case 100:
caps.add(Caps.GLSL100);
break;
}
if (!caps.contains(Caps.GLSL100)) {
logger.log(Level.WARNING, "Force-adding GLSL100 support, since OpenGL2 is supported.");
caps.add(Caps.GLSL100);
}
gl.glGetIntegerv(GL2ES2.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, intBuf16); gl.glGetIntegerv(GL2ES2.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, intBuf16);
vertexTextureUnits = intBuf16.get(0); vertexTextureUnits = intBuf16.get(0);
logger.log(Level.FINER, "VTF Units: {0}", vertexTextureUnits); logger.log(Level.FINER, "VTF Units: {0}", vertexTextureUnits);
@ -276,68 +268,84 @@ public class JoglRenderer implements Renderer {
maxCubeTexSize = intBuf16.get(0); maxCubeTexSize = intBuf16.get(0);
logger.log(Level.FINER, "Maximum CubeMap Resolution: {0}", maxCubeTexSize); logger.log(Level.FINER, "Maximum CubeMap Resolution: {0}", maxCubeTexSize);
// if (gl.isExtensionAvailable("GL_ARB_color_buffer_float")) { if (gl.isExtensionAvailable("GL_ARB_color_buffer_float")) {
// XXX: Require both 16 and 32 bit float support for FloatColorBuffer. // XXX: Require both 16 and 32 bit float support for FloatColorBuffer.
// if (gl.isExtensionAvailable("GL_ARB_half_float_pixel")) { if (gl.isExtensionAvailable("GL_ARB_half_float_pixel")) {
caps.add(Caps.FloatColorBuffer); caps.add(Caps.FloatColorBuffer);
// } }
// } }
if (gl.isExtensionAvailable("GL_ARB_depth_buffer_float")) {
caps.add(Caps.FloatDepthBuffer);
}
// if (gl.isExtensionAvailable("GL_ARB_depth_buffer_float")) {
caps.add(Caps.FloatDepthBuffer);
// }
// if (gl.isExtensionAvailable("GL_ARB_draw_instanced")) { if (gl.isExtensionAvailable("GL_ARB_draw_instanced")) {
// caps.add(Caps.MeshInstancing); caps.add(Caps.MeshInstancing);
// } }
// if (gl.isExtensionAvailable("GL_ARB_fragment_program")) { if (gl.isExtensionAvailable("GL_ARB_fragment_program")) {
caps.add(Caps.ARBprogram); caps.add(Caps.ARBprogram);
// } }
// if (gl.isExtensionAvailable("GL_ARB_texture_buffer_object")) { if (gl.isExtensionAvailable("GL_ARB_texture_buffer_object")) {
caps.add(Caps.TextureBuffer); caps.add(Caps.TextureBuffer);
// } }
// if (gl.isExtensionAvailable("GL_ARB_texture_float")) { if (gl.isExtensionAvailable("GL_ARB_texture_float")) {
// if (gl.isExtensionAvailable("GL_ARB_half_float_pixel")) { if (gl.isExtensionAvailable("GL_ARB_half_float_pixel")) {
caps.add(Caps.FloatTexture); caps.add(Caps.FloatTexture);
// } }
// } }
// if (gl.isExtensionAvailable("GL_ARB_vertex_array_object")) { if (gl.isExtensionAvailable("GL_ARB_vertex_array_object")) {
caps.add(Caps.VertexBufferArray); caps.add(Caps.VertexBufferArray);
// } }
boolean latc = gl.isExtensionAvailable("GL_EXT_texture_compression_latc"); boolean latc = gl.isExtensionAvailable("GL_EXT_texture_compression_latc");
//FIXME ignore atdc?
boolean atdc = gl.isExtensionAvailable("GL_ATI_texture_compression_3dc"); boolean atdc = gl.isExtensionAvailable("GL_ATI_texture_compression_3dc");
if (latc || atdc) { if (latc || atdc) {
caps.add(Caps.TextureCompressionLATC); caps.add(Caps.TextureCompressionLATC);
if (atdc && !latc) {
tdc = true;
}
} }
// if (gl.isExtensionAvailable("GL_EXT_packed_float")) { if (gl.isExtensionAvailable("GL_EXT_packed_float")) {
caps.add(Caps.PackedFloatColorBuffer); caps.add(Caps.PackedFloatColorBuffer);
// if (gl.isExtensionAvailable("GL_ARB_half_float_pixel")) { if (gl.isExtensionAvailable("GL_ARB_half_float_pixel")) {
// because textures are usually uploaded as RGB16F // because textures are usually uploaded as RGB16F
// need half-float pixel // need half-float pixel
caps.add(Caps.PackedFloatTexture); caps.add(Caps.PackedFloatTexture);
// } }
// } }
// if (gl.isExtensionAvailable("GL_EXT_texture_array")) { if (gl.isExtensionAvailable("GL_EXT_texture_array")) {
caps.add(Caps.TextureArray); caps.add(Caps.TextureArray);
// } }
// if (gl.isExtensionAvailable("GL_EXT_texture_shared_exponent")) { if (gl.isExtensionAvailable("GL_EXT_texture_shared_exponent")) {
caps.add(Caps.SharedExponentTexture); caps.add(Caps.SharedExponentTexture);
// } }
if (gl.isExtensionAvailable("GL_EXT_framebuffer_object")) { if (gl.isExtensionAvailable("GL_EXT_framebuffer_object")) {
caps.add(Caps.FrameBuffer); caps.add(Caps.FrameBuffer);
gl.glGetIntegerv(GL.GL_MAX_RENDERBUFFER_SIZE, intBuf16);
maxRBSize = intBuf16.get(0);
logger.log(Level.FINER, "FBO RB Max Size: {0}", maxRBSize);
gl.glGetIntegerv(GL2GL3.GL_MAX_COLOR_ATTACHMENTS, intBuf16);
maxFBOAttachs = intBuf16.get(0);
logger.log(Level.FINER, "FBO Max renderbuffers: {0}", maxFBOAttachs);
if (gl.isExtensionAvailable("GL_EXT_framebuffer_multisample")) {
caps.add(Caps.FrameBufferMultisample);
gl.glGetIntegerv(GL2GL3.GL_MAX_SAMPLES, intBuf16);
maxFBOSamples = intBuf16.get(0);
logger.log(Level.FINER, "FBO Max Samples: {0}", maxFBOSamples);
}
if (gl.isExtensionAvailable("GL_ARB_texture_multisample")) { if (gl.isExtensionAvailable("GL_ARB_texture_multisample")) {
caps.add(Caps.TextureMultisample); caps.add(Caps.TextureMultisample);
@ -349,43 +357,34 @@ public class JoglRenderer implements Renderer {
maxDepthTexSamples = intBuf16.get(0); maxDepthTexSamples = intBuf16.get(0);
logger.log(Level.FINER, "Texture Multisample Depth Samples: {0}", maxDepthTexSamples); logger.log(Level.FINER, "Texture Multisample Depth Samples: {0}", maxDepthTexSamples);
} }
}
gl.glGetIntegerv(GL.GL_MAX_RENDERBUFFER_SIZE, intBuf16);
maxRBSize = intBuf16.get(0);
logger.log(Level.FINER, "FBO RB Max Size: {0}", maxRBSize);
gl.glGetIntegerv(GL2GL3.GL_MAX_COLOR_ATTACHMENTS, intBuf16);
maxFBOAttachs = intBuf16.get(0);
logger.log(Level.FINER, "FBO Max renderbuffers: {0}", maxFBOAttachs);
if (gl.isExtensionAvailable("GL_EXT_framebuffer_multisample")) {
caps.add(Caps.FrameBufferMultisample);
gl.glGetIntegerv(GL2GL3.GL_MAX_SAMPLES, intBuf16);
maxFBOSamples = intBuf16.get(0);
logger.log(Level.FINER, "FBO Max Samples: {0}", maxFBOSamples);
}
if (gl.isExtensionAvailable("GL_ARB_draw_buffers")) {
caps.add(Caps.FrameBufferMRT);
gl.glGetIntegerv(GL2GL3.GL_MAX_DRAW_BUFFERS, intBuf16); gl.glGetIntegerv(GL2GL3.GL_MAX_DRAW_BUFFERS, intBuf16);
maxMRTFBOAttachs = intBuf16.get(0); maxMRTFBOAttachs = intBuf16.get(0);
logger.log(Level.FINER, "FBO Max MRT renderbuffers: {0}", maxMRTFBOAttachs); if (maxMRTFBOAttachs > 1) {
caps.add(Caps.FrameBufferMRT);
logger.log(Level.FINER, "FBO Max MRT renderbuffers: {0}", maxMRTFBOAttachs);
}
//if (gl.isExtensionAvailable("GL_ARB_draw_buffers")) {
// caps.add(Caps.FrameBufferMRT);
// gl.glGetIntegerv(GL2GL3.GL_MAX_DRAW_BUFFERS, intBuf16);
// maxMRTFBOAttachs = intBuf16.get(0);
// logger.log(Level.FINER, "FBO Max MRT renderbuffers: {0}", maxMRTFBOAttachs);
//}
} }
// }
// if (gl.isExtensionAvailable("GL_ARB_multisample")) { if (gl.isExtensionAvailable("GL_ARB_multisample")) {
gl.glGetIntegerv(GL.GL_SAMPLE_BUFFERS, intBuf16); gl.glGetIntegerv(GL.GL_SAMPLE_BUFFERS, intBuf16);
boolean available = intBuf16.get(0) != 0; boolean available = intBuf16.get(0) != 0;
gl.glGetIntegerv(GL.GL_SAMPLES, intBuf16); gl.glGetIntegerv(GL.GL_SAMPLES, intBuf16);
int samples = intBuf16.get(0); int samples = intBuf16.get(0);
logger.log(Level.FINER, "Samples: {0}", samples); logger.log(Level.FINER, "Samples: {0}", samples);
boolean enabled = gl.glIsEnabled(GL.GL_MULTISAMPLE); boolean enabled = gl.glIsEnabled(GL.GL_MULTISAMPLE);
if (samples > 0 && available && !enabled) { if (samples > 0 && available && !enabled) {
gl.glEnable(GL.GL_MULTISAMPLE); gl.glEnable(GL.GL_MULTISAMPLE);
}
caps.add(Caps.Multisample);
} }
// }
} }
public EnumSet<Caps> getCaps() { public EnumSet<Caps> getCaps() {
@ -442,8 +441,7 @@ public class JoglRenderer implements Renderer {
if (state.isWireframe() && !context.wireframe) { if (state.isWireframe() && !context.wireframe) {
gl.getGL2().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE); gl.getGL2().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
context.wireframe = true; context.wireframe = true;
} } else if (!state.isWireframe() && context.wireframe) {
else if (!state.isWireframe() && context.wireframe) {
gl.getGL2().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL); gl.getGL2().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
context.wireframe = false; context.wireframe = false;
} }
@ -451,8 +449,7 @@ public class JoglRenderer implements Renderer {
gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL); gl.glDepthFunc(GL.GL_LEQUAL);
context.depthTestEnabled = true; context.depthTestEnabled = true;
} } else if (!state.isDepthTest() && context.depthTestEnabled) {
else if (!state.isDepthTest() && context.depthTestEnabled) {
gl.glDisable(GL.GL_DEPTH_TEST); gl.glDisable(GL.GL_DEPTH_TEST);
context.depthTestEnabled = false; context.depthTestEnabled = false;
} }
@ -460,24 +457,21 @@ public class JoglRenderer implements Renderer {
gl.glEnable(GL2ES1.GL_ALPHA_TEST); gl.glEnable(GL2ES1.GL_ALPHA_TEST);
gl.getGL2().glAlphaFunc(GL.GL_GREATER, state.getAlphaFallOff()); gl.getGL2().glAlphaFunc(GL.GL_GREATER, state.getAlphaFallOff());
context.alphaTestFallOff = state.getAlphaFallOff(); context.alphaTestFallOff = state.getAlphaFallOff();
} } else if (!state.isAlphaTest() && context.alphaTestFallOff != 0) {
else if (!state.isAlphaTest() && context.alphaTestFallOff != 0) {
gl.glDisable(GL2ES1.GL_ALPHA_TEST); gl.glDisable(GL2ES1.GL_ALPHA_TEST);
context.alphaTestFallOff = 0; context.alphaTestFallOff = 0;
} }
if (state.isDepthWrite() && !context.depthWriteEnabled) { if (state.isDepthWrite() && !context.depthWriteEnabled) {
gl.glDepthMask(true); gl.glDepthMask(true);
context.depthWriteEnabled = true; context.depthWriteEnabled = true;
} } else if (!state.isDepthWrite() && context.depthWriteEnabled) {
else if (!state.isDepthWrite() && context.depthWriteEnabled) {
gl.glDepthMask(false); gl.glDepthMask(false);
context.depthWriteEnabled = false; context.depthWriteEnabled = false;
} }
if (state.isColorWrite() && !context.colorWriteEnabled) { if (state.isColorWrite() && !context.colorWriteEnabled) {
gl.glColorMask(true, true, true, true); gl.glColorMask(true, true, true, true);
context.colorWriteEnabled = true; context.colorWriteEnabled = true;
} } else if (!state.isColorWrite() && context.colorWriteEnabled) {
else if (!state.isColorWrite() && context.colorWriteEnabled) {
gl.glColorMask(false, false, false, false); gl.glColorMask(false, false, false, false);
context.colorWriteEnabled = false; context.colorWriteEnabled = false;
} }
@ -488,8 +482,7 @@ public class JoglRenderer implements Renderer {
context.polyOffsetEnabled = true; context.polyOffsetEnabled = true;
context.polyOffsetFactor = state.getPolyOffsetFactor(); context.polyOffsetFactor = state.getPolyOffsetFactor();
context.polyOffsetUnits = state.getPolyOffsetUnits(); context.polyOffsetUnits = state.getPolyOffsetUnits();
} } else {
else {
if (state.getPolyOffsetFactor() != context.polyOffsetFactor if (state.getPolyOffsetFactor() != context.polyOffsetFactor
|| state.getPolyOffsetUnits() != context.polyOffsetUnits) { || state.getPolyOffsetUnits() != context.polyOffsetUnits) {
gl.glPolygonOffset(state.getPolyOffsetFactor(), state.getPolyOffsetUnits()); gl.glPolygonOffset(state.getPolyOffsetFactor(), state.getPolyOffsetUnits());
@ -497,8 +490,7 @@ public class JoglRenderer implements Renderer {
context.polyOffsetUnits = state.getPolyOffsetUnits(); context.polyOffsetUnits = state.getPolyOffsetUnits();
} }
} }
} } else {
else {
if (context.polyOffsetEnabled) { if (context.polyOffsetEnabled) {
gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
context.polyOffsetEnabled = false; context.polyOffsetEnabled = false;
@ -509,8 +501,7 @@ public class JoglRenderer implements Renderer {
if (state.getFaceCullMode() != context.cullMode) { if (state.getFaceCullMode() != context.cullMode) {
if (state.getFaceCullMode() == RenderState.FaceCullMode.Off) { if (state.getFaceCullMode() == RenderState.FaceCullMode.Off) {
gl.glDisable(GL.GL_CULL_FACE); gl.glDisable(GL.GL_CULL_FACE);
} } else {
else {
gl.glEnable(GL.GL_CULL_FACE); gl.glEnable(GL.GL_CULL_FACE);
} }
@ -537,8 +528,7 @@ public class JoglRenderer implements Renderer {
if (state.getBlendMode() != context.blendMode) { if (state.getBlendMode() != context.blendMode) {
if (state.getBlendMode() == RenderState.BlendMode.Off) { if (state.getBlendMode() == RenderState.BlendMode.Off) {
gl.glDisable(GL.GL_BLEND); gl.glDisable(GL.GL_BLEND);
} } else {
else {
gl.glEnable(GL.GL_BLEND); gl.glEnable(GL.GL_BLEND);
} }
@ -643,71 +633,71 @@ public class JoglRenderer implements Renderer {
public void setLighting(LightList list) { public void setLighting(LightList list) {
/*GL gl = GLContext.getCurrentGL(); /*GL gl = GLContext.getCurrentGL();
if (list == null || list.size() == 0) { if (list == null || list.size() == 0) {
// turn off lighting // turn off lighting
gl.glDisable(GLLightingFunc.GL_LIGHTING); gl.glDisable(GLLightingFunc.GL_LIGHTING);
return; return;
} }
gl.glEnable(GLLightingFunc.GL_LIGHTING); gl.glEnable(GLLightingFunc.GL_LIGHTING);
gl.getGL2().glShadeModel(GLLightingFunc.GL_SMOOTH); gl.getGL2().glShadeModel(GLLightingFunc.GL_SMOOTH);
float[] temp = new float[4]; float[] temp = new float[4];
// reset model view to specify // reset model view to specify
// light positions in world space // light positions in world space
// instead of model space // instead of model space
// gl.glPushMatrix(); // gl.glPushMatrix();
// gl.glLoadIdentity(); // gl.glLoadIdentity();
for (int i = 0; i < list.size() + 1; i++) { for (int i = 0; i < list.size() + 1; i++) {
int lightId = GLLightingFunc.GL_LIGHT0 + i; int lightId = GLLightingFunc.GL_LIGHT0 + i;
if (list.size() <= i) { if (list.size() <= i) {
// goes beyond the num lights we need // goes beyond the num lights we need
// disable it // disable it
gl.glDisable(lightId); gl.glDisable(lightId);
break; break;
} }
Light l = list.get(i); Light l = list.get(i);
if (!l.isEnabled()) { if (!l.isEnabled()) {
gl.glDisable(lightId); gl.glDisable(lightId);
continue; continue;
} }
ColorRGBA color = l.getColor(); ColorRGBA color = l.getColor();
color.toArray(temp); color.toArray(temp);
gl.glEnable(lightId); gl.glEnable(lightId);
gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_DIFFUSE, temp, 0); gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_DIFFUSE, temp, 0);
gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_SPECULAR, temp, 0); gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_SPECULAR, temp, 0);
ColorRGBA.Black.toArray(temp); ColorRGBA.Black.toArray(temp);
gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_AMBIENT, temp, 0); gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_AMBIENT, temp, 0);
switch (l.getType()) { switch (l.getType()) {
case Directional: case Directional:
DirectionalLight dl = (DirectionalLight) l; DirectionalLight dl = (DirectionalLight) l;
dl.getDirection().toArray(temp); dl.getDirection().toArray(temp);
temp[3] = 0f; // marks to GL its a directional light temp[3] = 0f; // marks to GL its a directional light
gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_POSITION, temp, 0); gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_POSITION, temp, 0);
break; break;
case Point: case Point:
PointLight pl = (PointLight) l; PointLight pl = (PointLight) l;
pl.getPosition().toArray(temp); pl.getPosition().toArray(temp);
temp[3] = 1f; // marks to GL its a point light temp[3] = 1f; // marks to GL its a point light
gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_POSITION, temp, 0); gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_POSITION, temp, 0);
break; break;
} }
} }
// restore modelview to original value // restore modelview to original value
// gl.glPopMatrix(); // gl.glPopMatrix();
* */ * */
} }
public void deleteShaderSource(ShaderSource source) { public void deleteShaderSource(ShaderSource source) {
@ -748,8 +738,7 @@ public class JoglRenderer implements Renderer {
} }
lastFb = null; lastFb = null;
} } else {
else {
if (fb.isUpdateNeeded()) { if (fb.isUpdateNeeded()) {
updateFrameBuffer(fb); updateFrameBuffer(fb);
} }
@ -762,8 +751,7 @@ public class JoglRenderer implements Renderer {
setViewPort(0, 0, fb.getWidth(), fb.getHeight()); setViewPort(0, 0, fb.getWidth(), fb.getHeight());
context.boundFBO = fb.getId(); context.boundFBO = fb.getId();
} } else {
else {
statistics.onFrameBufferUse(fb, false); statistics.onFrameBufferUse(fb, false);
} }
if (fb.getNumColorBuffers() == 0) { if (fb.getNumColorBuffers() == 0) {
@ -777,8 +765,7 @@ public class JoglRenderer implements Renderer {
gl.getGL2().glReadBuffer(GL.GL_NONE); gl.getGL2().glReadBuffer(GL.GL_NONE);
context.boundReadBuf = -2; context.boundReadBuf = -2;
} }
} } else {
else {
if (fb.isMultiTarget()) { if (fb.isMultiTarget()) {
if (fb.getNumColorBuffers() > maxMRTFBOAttachs) { if (fb.getNumColorBuffers() > maxMRTFBOAttachs) {
throw new UnsupportedOperationException("Framebuffer has more" throw new UnsupportedOperationException("Framebuffer has more"
@ -795,8 +782,7 @@ public class JoglRenderer implements Renderer {
gl.getGL2().glDrawBuffers(intBuf16.limit(), intBuf16); gl.getGL2().glDrawBuffers(intBuf16.limit(), intBuf16);
context.boundDrawBuf = 100 + fb.getNumColorBuffers(); context.boundDrawBuf = 100 + fb.getNumColorBuffers();
} }
} } else {
else {
RenderBuffer rb = fb.getColorBuffer(fb.getTargetIndex()); RenderBuffer rb = fb.getColorBuffer(fb.getTargetIndex());
// select this draw buffer // select this draw buffer
if (context.boundDrawBuf != rb.getSlot()) { if (context.boundDrawBuf != rb.getSlot()) {
@ -813,8 +799,7 @@ public class JoglRenderer implements Renderer {
try { try {
checkFrameBufferError(); checkFrameBufferError();
} } catch (IllegalStateException ex) {
catch (IllegalStateException ex) {
logger.log(Level.SEVERE, "Problem FBO:\n{0}", fb); logger.log(Level.SEVERE, "Problem FBO:\n{0}", fb);
throw ex; throw ex;
} }
@ -857,8 +842,7 @@ public class JoglRenderer implements Renderer {
// can also add support for stencil here // can also add support for stencil here
if (attachmentSlot == -100) { if (attachmentSlot == -100) {
return GL.GL_DEPTH_ATTACHMENT; return GL.GL_DEPTH_ATTACHMENT;
} } else if (attachmentSlot < 0 || attachmentSlot >= 16) {
else if (attachmentSlot < 0 || attachmentSlot >= 16) {
throw new UnsupportedOperationException("Invalid FBO attachment slot: " throw new UnsupportedOperationException("Invalid FBO attachment slot: "
+ attachmentSlot); + attachmentSlot);
} }
@ -890,8 +874,7 @@ public class JoglRenderer implements Renderer {
// if it hasn't been created yet, then attach is required. // if it hasn't been created yet, then attach is required.
needAttach = rb.getId() == -1; needAttach = rb.getId() == -1;
updateRenderBuffer(fb, rb); updateRenderBuffer(fb, rb);
} } else {
else {
needAttach = false; needAttach = false;
updateRenderTexture(fb, rb); updateRenderTexture(fb, rb);
} }
@ -962,10 +945,9 @@ public class JoglRenderer implements Renderer {
} }
gl.getGL2() gl.getGL2()
.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, samples, .glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, samples,
TextureUtil.convertTextureFormat(rb.getFormat()), fb.getWidth(), TextureUtil.convertTextureFormat(rb.getFormat()), fb.getWidth(),
fb.getHeight()); fb.getHeight());
} } else {
else {
gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, gl.glRenderbufferStorage(GL.GL_RENDERBUFFER,
TextureUtil.convertTextureFormat(rb.getFormat()), fb.getWidth(), fb.getHeight()); TextureUtil.convertTextureFormat(rb.getFormat()), fb.getWidth(), fb.getHeight());
} }
@ -1114,7 +1096,8 @@ public class JoglRenderer implements Renderer {
* *
* @param img The image to upload * @param img The image to upload
* @param type How the data in the image argument should be interpreted. * @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 unit The texture slot to be used to upload the image, not
* important
*/ */
public void updateTexImageData(Image img, Texture.Type type, int unit) { public void updateTexImageData(Image img, Texture.Type type, int unit) {
int texId = img.getId(); int texId = img.getId();
@ -1277,19 +1260,19 @@ public class JoglRenderer implements Renderer {
public void clearTextureUnits() { public void clearTextureUnits() {
/*GL gl = GLContext.getCurrentGL(); /*GL gl = GLContext.getCurrentGL();
IDList textureList = context.textureIndexList; IDList textureList = context.textureIndexList;
Texture[] textures = context.boundTextures; Texture[] textures = context.boundTextures;
for (int i = 0; i < textureList.oldLen; i++) { for (int i = 0; i < textureList.oldLen; i++) {
int idx = textureList.oldList[i]; int idx = textureList.oldList[i];
if (context.boundTextureUnit != idx) { if (context.boundTextureUnit != idx) {
gl.glActiveTexture(GL.GL_TEXTURE0 + idx); gl.glActiveTexture(GL.GL_TEXTURE0 + idx);
context.boundTextureUnit = idx; context.boundTextureUnit = idx;
} }
gl.glDisable(convertTextureType(textures[idx].getType())); gl.glDisable(convertTextureType(textures[idx].getType()));
textures[idx] = null; textures[idx] = null;
} }
context.textureIndexList.copyNewToOld();*/ context.textureIndexList.copyNewToOld();*/
} }
public void deleteImage(Image image) { public void deleteImage(Image image) {
@ -1336,8 +1319,7 @@ public class JoglRenderer implements Renderer {
gl.glBindBuffer(target, bufId); gl.glBindBuffer(target, bufId);
context.boundElementArrayVBO = bufId; context.boundElementArrayVBO = bufId;
} }
} } else {
else {
target = GL.GL_ARRAY_BUFFER; target = GL.GL_ARRAY_BUFFER;
if (context.boundArrayVBO != bufId) { if (context.boundArrayVBO != bufId) {
gl.glBindBuffer(target, bufId); gl.glBindBuffer(target, bufId);
@ -1452,8 +1434,7 @@ public class JoglRenderer implements Renderer {
if (vb.isNormalized() && !context.normalizeEnabled) { if (vb.isNormalized() && !context.normalizeEnabled) {
gl.glEnable(GLLightingFunc.GL_NORMALIZE); gl.glEnable(GLLightingFunc.GL_NORMALIZE);
context.normalizeEnabled = true; context.normalizeEnabled = true;
} } else if (!vb.isNormalized() && context.normalizeEnabled) {
else if (!vb.isNormalized() && context.normalizeEnabled) {
gl.glDisable(GLLightingFunc.GL_NORMALIZE); gl.glDisable(GLLightingFunc.GL_NORMALIZE);
context.normalizeEnabled = false; context.normalizeEnabled = false;
} }
@ -1510,8 +1491,7 @@ public class JoglRenderer implements Renderer {
for (int i = 0; i < elementLengths.length; i++) { for (int i = 0; i < elementLengths.length; i++) {
if (i == stripStart) { if (i == stripStart) {
elMode = convertElementMode(Mode.TriangleStrip); elMode = convertElementMode(Mode.TriangleStrip);
} } else if (i == fanStart) {
else if (i == fanStart) {
//TriangleStrip? //TriangleStrip?
elMode = convertElementMode(Mode.TriangleFan); elMode = convertElementMode(Mode.TriangleFan);
} }
@ -1519,8 +1499,7 @@ public class JoglRenderer implements Renderer {
gl.glDrawElements(elMode, elementLength, fmt, curOffset); gl.glDrawElements(elMode, elementLength, fmt, curOffset);
curOffset += elementLength * elSize; curOffset += elementLength * elSize;
} }
} } else {
else {
gl.glDrawElements(convertElementMode(mesh.getMode()), indexBuf.getData().capacity(), gl.glDrawElements(convertElementMode(mesh.getMode()), indexBuf.getData().capacity(),
convertVertexFormat(indexBuf.getFormat()), 0); convertVertexFormat(indexBuf.getFormat()), 0);
} }
@ -1541,8 +1520,7 @@ public class JoglRenderer implements Renderer {
if (vb.isNormalized() && !context.normalizeEnabled) { if (vb.isNormalized() && !context.normalizeEnabled) {
gl.glEnable(GLLightingFunc.GL_NORMALIZE); gl.glEnable(GLLightingFunc.GL_NORMALIZE);
context.normalizeEnabled = true; context.normalizeEnabled = true;
} } else if (!vb.isNormalized() && context.normalizeEnabled) {
else if (!vb.isNormalized() && context.normalizeEnabled) {
gl.glDisable(GLLightingFunc.GL_NORMALIZE); gl.glDisable(GLLightingFunc.GL_NORMALIZE);
context.normalizeEnabled = false; context.normalizeEnabled = false;
} }
@ -1607,8 +1585,7 @@ public class JoglRenderer implements Renderer {
for (int i = 0; i < elementLengths.length; i++) { for (int i = 0; i < elementLengths.length; i++) {
if (i == stripStart) { if (i == stripStart) {
elMode = convertElementMode(Mode.TriangleStrip); elMode = convertElementMode(Mode.TriangleStrip);
} } else if (i == fanStart) {
else if (i == fanStart) {
elMode = convertElementMode(Mode.TriangleStrip); elMode = convertElementMode(Mode.TriangleStrip);
} }
int elementLength = elementLengths[i]; int elementLength = elementLengths[i];
@ -1616,8 +1593,7 @@ public class JoglRenderer implements Renderer {
gl.glDrawElements(elMode, elementLength, fmt, indexData); gl.glDrawElements(elMode, elementLength, fmt, indexData);
curOffset += elementLength; curOffset += elementLength;
} }
} } else {
else {
gl.glDrawElements(convertElementMode(mode), indexData.capacity(), gl.glDrawElements(convertElementMode(mode), indexData.capacity(),
convertVertexFormat(indexBuf.getFormat()), indexData); convertVertexFormat(indexBuf.getFormat()), indexData);
} }
@ -1629,8 +1605,7 @@ public class JoglRenderer implements Renderer {
IntMap<VertexBuffer> buffers = mesh.getBuffers(); IntMap<VertexBuffer> buffers = mesh.getBuffers();
if (mesh.getNumLodLevels() > 0) { if (mesh.getNumLodLevels() > 0) {
indices = mesh.getLodLevel(lod); indices = mesh.getLodLevel(lod);
} } else {
else {
indices = buffers.get(Type.Index.ordinal()); indices = buffers.get(Type.Index.ordinal());
} }
for (Entry<VertexBuffer> entry : buffers) { for (Entry<VertexBuffer> entry : buffers) {
@ -1642,13 +1617,11 @@ public class JoglRenderer implements Renderer {
if (vb.getBufferType() == Type.Index) { if (vb.getBufferType() == Type.Index) {
indices = vb; indices = vb;
} } else {
else {
if (vb.getStride() == 0) { if (vb.getStride() == 0) {
// not interleaved // not interleaved
setVertexAttrib(vb); setVertexAttrib(vb);
} } else {
else {
// interleaved // interleaved
setVertexAttrib(vb, interleavedData); setVertexAttrib(vb, interleavedData);
} }
@ -1657,8 +1630,7 @@ public class JoglRenderer implements Renderer {
if (indices != null) { if (indices != null) {
drawTriangleList(indices, mesh, count); drawTriangleList(indices, mesh, count);
} } else {
else {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
} }
@ -1676,16 +1648,15 @@ public class JoglRenderer implements Renderer {
IntMap<VertexBuffer> buffers = mesh.getBuffers(); IntMap<VertexBuffer> buffers = mesh.getBuffers();
if (mesh.getNumLodLevels() > 0) { if (mesh.getNumLodLevels() > 0) {
indices = mesh.getLodLevel(lod); indices = mesh.getLodLevel(lod);
} } else {
else {
indices = buffers.get(Type.Index.ordinal()); indices = buffers.get(Type.Index.ordinal());
} }
for (Entry<VertexBuffer> entry : buffers) { for (Entry<VertexBuffer> entry : buffers) {
VertexBuffer vb = entry.getValue(); VertexBuffer vb = entry.getValue();
if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly // ignore if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly // ignore
// cpu-only // cpu-only
// buffers // buffers
|| vb.getBufferType() == Type.Index) { || vb.getBufferType() == Type.Index) {
continue; continue;
} }
@ -1693,8 +1664,7 @@ public class JoglRenderer implements Renderer {
if (vb.getStride() == 0) { if (vb.getStride() == 0) {
// not interleaved // not interleaved
setVertexAttribVBO(vb, null); setVertexAttribVBO(vb, null);
} } else {
else {
// interleaved // interleaved
setVertexAttribVBO(vb, interleavedData); setVertexAttribVBO(vb, interleavedData);
} }
@ -1702,8 +1672,7 @@ public class JoglRenderer implements Renderer {
if (indices != null) { if (indices != null) {
drawTriangleListVBO(indices, mesh, count); drawTriangleListVBO(indices, mesh, count);
} } else {
else {
gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
} }
clearVertexAttribs(); clearVertexAttribs();
@ -1753,10 +1722,9 @@ public class JoglRenderer implements Renderer {
checkTexturingUsed(); checkTexturingUsed();
if (vbo) { /*if (vbo) {*/
renderMeshVBO(mesh, lod, count); renderMeshVBO(mesh, lod, count);
} /*} else {
else {
boolean dynamic = false; boolean dynamic = false;
if (mesh.getNumLodLevels() == 0) { if (mesh.getNumLodLevels() == 0) {
IntMap<VertexBuffer> bufs = mesh.getBuffers(); IntMap<VertexBuffer> bufs = mesh.getBuffers();
@ -1766,19 +1734,17 @@ public class JoglRenderer implements Renderer {
break; break;
} }
} }
} } else {
else {
dynamic = true; dynamic = true;
} }
if (!dynamic) { if (!dynamic) {
// dealing with a static object, generate display list // dealing with a static object, generate display list
renderMeshDisplayList(mesh); renderMeshDisplayList(mesh);
} } else {
else {
renderMeshDefault(mesh, lod, count); renderMeshDefault(mesh, lod, count);
} }
} }*/
} }
public void invalidateState() { public void invalidateState() {

Loading…
Cancel
Save