Improves OpenGL-ES support (especially for Raspberry Pi), uses several contributions of Erkki Nokso-Koivisto

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10264 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
jul..om 12 years ago
parent 5d24544589
commit b242f66c5a
  1. 27
      engine/src/jogl/com/jme3/renderer/jogl/JoglGL1Renderer.java
  2. 394
      engine/src/jogl/com/jme3/renderer/jogl/JoglRenderer.java

@ -62,6 +62,7 @@ import java.util.EnumSet;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.media.opengl.*; import javax.media.opengl.*;
import javax.media.opengl.fixedfunc.GLLightingFunc;
import jme3tools.converters.MipMapGenerator; import jme3tools.converters.MipMapGenerator;
public class JoglGL1Renderer implements GL1Renderer { public class JoglGL1Renderer implements GL1Renderer {
@ -120,16 +121,16 @@ public class JoglGL1Renderer implements GL1Renderer {
} }
// Default values for certain GL state. // Default values for certain GL state.
gl.getGL2().glShadeModel(GL2.GL_SMOOTH); gl.getGL2ES1().glShadeModel(GLLightingFunc.GL_SMOOTH);
gl.getGL2().glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE); gl.getGL2().glColorMaterial(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_DIFFUSE);
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
// Enable rescaling/normaling of normal vectors. // Enable rescaling/normaling of normal vectors.
// Fixes lighting issues with scaled models. // Fixes lighting issues with scaled models.
if (gl12){ if (gl12){
gl.glEnable(GL2.GL_RESCALE_NORMAL); gl.glEnable(GL2ES1.GL_RESCALE_NORMAL);
}else{ }else{
gl.glEnable(GL2.GL_NORMALIZE); gl.glEnable(GLLightingFunc.GL_NORMALIZE);
} }
if (gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two")) { if (gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two")) {
@ -140,7 +141,7 @@ public class JoglGL1Renderer implements GL1Renderer {
+ "Some features might not work."); + "Some features might not work.");
} }
gl.glGetIntegerv(GL2.GL_MAX_LIGHTS, ib1); gl.glGetIntegerv(GL2ES1.GL_MAX_LIGHTS, ib1);
maxLights = ib1.get(0); maxLights = ib1.get(0);
gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, ib1); gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, ib1);
@ -167,7 +168,7 @@ public class JoglGL1Renderer implements GL1Renderer {
public void setDepthRange(float start, float end) { public void setDepthRange(float start, float end) {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
gl.getGL2().glDepthRange(start, end); gl.getGL2ES2().glDepthRange(start, end);
} }
public void clearBuffers(boolean color, boolean depth, boolean stencil) { public void clearBuffers(boolean color, boolean depth, boolean stencil) {
@ -222,15 +223,15 @@ public class JoglGL1Renderer implements GL1Renderer {
private void applyFixedFuncBindings(boolean forLighting){ private void applyFixedFuncBindings(boolean forLighting){
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
if (forLighting) { if (forLighting) {
gl.getGL2().glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, context.shininess); gl.getGL2().glMaterialf(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SHININESS, context.shininess);
setMaterialColor(GL2.GL_AMBIENT, context.ambient, ColorRGBA.DarkGray); setMaterialColor(GLLightingFunc.GL_AMBIENT, context.ambient, ColorRGBA.DarkGray);
setMaterialColor(GL2.GL_DIFFUSE, context.diffuse, ColorRGBA.White); setMaterialColor(GLLightingFunc.GL_DIFFUSE, context.diffuse, ColorRGBA.White);
setMaterialColor(GL2.GL_SPECULAR, context.specular, ColorRGBA.Black); setMaterialColor(GLLightingFunc.GL_SPECULAR, context.specular, ColorRGBA.Black);
if (context.useVertexColor) { if (context.useVertexColor) {
gl.glEnable(GL2.GL_COLOR_MATERIAL); gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL);
} else { } else {
gl.glDisable(GL2.GL_COLOR_MATERIAL); gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL);
} }
} else { } else {
// Ignore other values as they have no effect when // Ignore other values as they have no effect when

@ -64,7 +64,6 @@ import com.jme3.util.BufferUtils;
import com.jme3.util.ListMap; import com.jme3.util.ListMap;
import com.jme3.util.NativeObjectManager; import com.jme3.util.NativeObjectManager;
import com.jme3.util.SafeArrayList; import com.jme3.util.SafeArrayList;
import com.jogamp.common.nio.Buffers;
import java.nio.*; import java.nio.*;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
@ -72,6 +71,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.media.opengl.GL; import javax.media.opengl.GL;
import javax.media.opengl.GL2; import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GL2ES2; import javax.media.opengl.GL2ES2;
import javax.media.opengl.GL2GL3; import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLContext; import javax.media.opengl.GLContext;
@ -361,16 +361,16 @@ public class JoglRenderer implements Renderer {
if (gl.isExtensionAvailable("GL_ARB_texture_multisample")) { if (gl.isExtensionAvailable("GL_ARB_texture_multisample")) {
caps.add(Caps.TextureMultisample); caps.add(Caps.TextureMultisample);
gl.glGetIntegerv(GL2.GL_MAX_COLOR_TEXTURE_SAMPLES, intBuf16); gl.glGetIntegerv(GL2GL3.GL_MAX_COLOR_TEXTURE_SAMPLES, intBuf16);
maxColorTexSamples = intBuf16.get(0); maxColorTexSamples = intBuf16.get(0);
logger.log(Level.FINER, "Texture Multisample Color Samples: {0}", maxColorTexSamples); logger.log(Level.FINER, "Texture Multisample Color Samples: {0}", maxColorTexSamples);
gl.glGetIntegerv(GL2.GL_MAX_DEPTH_TEXTURE_SAMPLES, intBuf16); gl.glGetIntegerv(GL2GL3.GL_MAX_DEPTH_TEXTURE_SAMPLES, intBuf16);
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(GL2GL3.GL_MAX_DRAW_BUFFERS, intBuf16); gl.glGetIntegerv(GL2ES2.GL_MAX_DRAW_BUFFERS, intBuf16);
maxMRTFBOAttachs = intBuf16.get(0); maxMRTFBOAttachs = intBuf16.get(0);
if (maxMRTFBOAttachs > 1) { if (maxMRTFBOAttachs > 1) {
caps.add(Caps.FrameBufferMRT); caps.add(Caps.FrameBufferMRT);
@ -407,9 +407,9 @@ public class JoglRenderer implements Renderer {
lastFb = null; lastFb = null;
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
gl.glGetIntegerv(GL2.GL_DRAW_BUFFER, intBuf1); gl.glGetIntegerv(GL2GL3.GL_DRAW_BUFFER, intBuf1);
initialDrawBuf = intBuf1.get(0); initialDrawBuf = intBuf1.get(0);
gl.glGetIntegerv(GL2.GL_READ_BUFFER, intBuf1); gl.glGetIntegerv(GL2GL3.GL_READ_BUFFER, intBuf1);
initialReadBuf = intBuf1.get(0); initialReadBuf = intBuf1.get(0);
} }
@ -481,9 +481,9 @@ public class JoglRenderer implements Renderer {
if (caps.contains(Caps.Multisample)) { if (caps.contains(Caps.Multisample)) {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
if (value) { if (value) {
gl.glEnable(GL2.GL_SAMPLE_ALPHA_TO_COVERAGE); gl.glEnable(GL.GL_SAMPLE_ALPHA_TO_COVERAGE);
} else { } else {
gl.glDisable(GL2.GL_SAMPLE_ALPHA_TO_COVERAGE); gl.glDisable(GL.GL_SAMPLE_ALPHA_TO_COVERAGE);
} }
} }
} }
@ -491,10 +491,14 @@ public class JoglRenderer implements Renderer {
public void applyRenderState(RenderState state) { public void applyRenderState(RenderState state) {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
if (state.isWireframe() && !context.wireframe) { if (state.isWireframe() && !context.wireframe) {
gl.getGL2GL3().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2.GL_LINE); if (gl.isGL2GL3()) {
gl.getGL2GL3().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.getGL2GL3().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2.GL_FILL); if (gl.isGL2GL3()) {
gl.getGL2GL3().glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
}
context.wireframe = false; context.wireframe = false;
} }
@ -508,11 +512,15 @@ public class JoglRenderer implements Renderer {
} }
if (state.isAlphaTest() && context.alphaTestFallOff == 0) { if (state.isAlphaTest() && context.alphaTestFallOff == 0) {
gl.glEnable(GL2.GL_ALPHA_TEST); gl.glEnable(GL2ES1.GL_ALPHA_TEST);
gl.getGL2().glAlphaFunc(GL.GL_GREATER, state.getAlphaFallOff()); if (gl.isGL2ES1()) {
gl.getGL2ES1().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(GL2.GL_ALPHA_TEST); if (gl.isGL2ES1()) {
gl.glDisable(GL2ES1.GL_ALPHA_TEST);
}
context.alphaTestFallOff = 0; context.alphaTestFallOff = 0;
} }
@ -539,8 +547,12 @@ public class JoglRenderer implements Renderer {
gl.glActiveTexture(GL.GL_TEXTURE0); gl.glActiveTexture(GL.GL_TEXTURE0);
context.boundTextureUnit = 0; context.boundTextureUnit = 0;
} }
gl.glEnable(GL2.GL_POINT_SPRITE); if (gl.isGL2ES1()) {
gl.glEnable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE); gl.glEnable(GL2ES1.GL_POINT_SPRITE);
}
if (gl.isGL2GL3()) {
gl.glEnable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
}
} }
context.pointSprite = true; context.pointSprite = true;
} else if (!state.isPointSprite() && context.pointSprite) { } else if (!state.isPointSprite() && context.pointSprite) {
@ -549,8 +561,12 @@ public class JoglRenderer implements Renderer {
gl.glActiveTexture(GL.GL_TEXTURE0); gl.glActiveTexture(GL.GL_TEXTURE0);
context.boundTextureUnit = 0; context.boundTextureUnit = 0;
} }
gl.glDisable(GL2.GL_POINT_SPRITE); if (gl.isGL2ES1()) {
gl.glDisable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE); gl.glDisable(GL2ES1.GL_POINT_SPRITE);
}
if (gl.isGL2GL3()) {
gl.glDisable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
}
context.pointSprite = false; context.pointSprite = false;
} }
} }
@ -667,18 +683,18 @@ public class JoglRenderer implements Renderer {
if (state.isStencilTest()) { if (state.isStencilTest()) {
gl.glEnable(GL.GL_STENCIL_TEST); gl.glEnable(GL.GL_STENCIL_TEST);
gl.getGL2GL3().glStencilOpSeparate(GL.GL_FRONT, gl.getGL2ES2().glStencilOpSeparate(GL.GL_FRONT,
convertStencilOperation(state.getFrontStencilStencilFailOperation()), convertStencilOperation(state.getFrontStencilStencilFailOperation()),
convertStencilOperation(state.getFrontStencilDepthFailOperation()), convertStencilOperation(state.getFrontStencilDepthFailOperation()),
convertStencilOperation(state.getFrontStencilDepthPassOperation())); convertStencilOperation(state.getFrontStencilDepthPassOperation()));
gl.getGL2GL3().glStencilOpSeparate(GL.GL_BACK, gl.getGL2ES2().glStencilOpSeparate(GL.GL_BACK,
convertStencilOperation(state.getBackStencilStencilFailOperation()), convertStencilOperation(state.getBackStencilStencilFailOperation()),
convertStencilOperation(state.getBackStencilDepthFailOperation()), convertStencilOperation(state.getBackStencilDepthFailOperation()),
convertStencilOperation(state.getBackStencilDepthPassOperation())); convertStencilOperation(state.getBackStencilDepthPassOperation()));
gl.getGL2GL3().glStencilFuncSeparate(GL.GL_FRONT, gl.getGL2ES2().glStencilFuncSeparate(GL.GL_FRONT,
convertTestFunction(state.getFrontStencilFunction()), convertTestFunction(state.getFrontStencilFunction()),
0, Integer.MAX_VALUE); 0, Integer.MAX_VALUE);
gl.getGL2GL3().glStencilFuncSeparate(GL.GL_BACK, gl.getGL2ES2().glStencilFuncSeparate(GL.GL_BACK,
convertTestFunction(state.getBackStencilFunction()), convertTestFunction(state.getBackStencilFunction()),
0, Integer.MAX_VALUE); 0, Integer.MAX_VALUE);
} else { } else {
@ -791,7 +807,7 @@ public class JoglRenderer implements Renderer {
protected void updateUniformLocation(Shader shader, Uniform uniform) { protected void updateUniformLocation(Shader shader, Uniform uniform) {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
// passing a null terminated string is not necessary with JOGL 2.0 // passing a null terminated string is not necessary with JOGL 2.0
int loc = gl.getGL2GL3().glGetUniformLocation(shader.getId(), uniform.getName()); int loc = gl.getGL2ES2().glGetUniformLocation(shader.getId(), uniform.getName());
if (loc < 0) { if (loc < 0) {
uniform.setLocation(-1); uniform.setLocation(-1);
// uniform is not declared in shader // uniform is not declared in shader
@ -806,7 +822,7 @@ public class JoglRenderer implements Renderer {
int shaderId = shader.getId(); int shaderId = shader.getId();
if (context.boundShaderProgram != shaderId) { if (context.boundShaderProgram != shaderId) {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
gl.getGL2GL3().glUseProgram(shaderId); gl.getGL2ES2().glUseProgram(shaderId);
statistics.onShaderUse(shader, true); statistics.onShaderUse(shader, true);
boundShader = shader; boundShader = shader;
context.boundShaderProgram = shaderId; context.boundShaderProgram = shaderId;
@ -850,66 +866,66 @@ public class JoglRenderer implements Renderer {
switch (uniform.getVarType()) { switch (uniform.getVarType()) {
case Float: case Float:
Float f = (Float) uniform.getValue(); Float f = (Float) uniform.getValue();
gl.getGL2GL3().glUniform1f(loc, f.floatValue()); gl.getGL2ES2().glUniform1f(loc, f.floatValue());
break; break;
case Vector2: case Vector2:
Vector2f v2 = (Vector2f) uniform.getValue(); Vector2f v2 = (Vector2f) uniform.getValue();
gl.getGL2GL3().glUniform2f(loc, v2.getX(), v2.getY()); gl.getGL2ES2().glUniform2f(loc, v2.getX(), v2.getY());
break; break;
case Vector3: case Vector3:
Vector3f v3 = (Vector3f) uniform.getValue(); Vector3f v3 = (Vector3f) uniform.getValue();
gl.getGL2GL3().glUniform3f(loc, v3.getX(), v3.getY(), v3.getZ()); gl.getGL2ES2().glUniform3f(loc, v3.getX(), v3.getY(), v3.getZ());
break; break;
case Vector4: case Vector4:
Object val = uniform.getValue(); Object val = uniform.getValue();
if (val instanceof ColorRGBA) { if (val instanceof ColorRGBA) {
ColorRGBA c = (ColorRGBA) val; ColorRGBA c = (ColorRGBA) val;
gl.getGL2GL3().glUniform4f(loc, c.r, c.g, c.b, c.a); gl.getGL2ES2().glUniform4f(loc, c.r, c.g, c.b, c.a);
} else if (val instanceof Vector4f) { } else if (val instanceof Vector4f) {
Vector4f c = (Vector4f) val; Vector4f c = (Vector4f) val;
gl.getGL2GL3().glUniform4f(loc, c.x, c.y, c.z, c.w); gl.getGL2ES2().glUniform4f(loc, c.x, c.y, c.z, c.w);
} else { } else {
Quaternion c = (Quaternion) uniform.getValue(); Quaternion c = (Quaternion) uniform.getValue();
gl.getGL2GL3().glUniform4f(loc, c.getX(), c.getY(), c.getZ(), c.getW()); gl.getGL2ES2().glUniform4f(loc, c.getX(), c.getY(), c.getZ(), c.getW());
} }
break; break;
case Boolean: case Boolean:
Boolean b = (Boolean) uniform.getValue(); Boolean b = (Boolean) uniform.getValue();
gl.getGL2GL3().glUniform1i(loc, b.booleanValue() ? GL.GL_TRUE : GL.GL_FALSE); gl.getGL2ES2().glUniform1i(loc, b.booleanValue() ? GL.GL_TRUE : GL.GL_FALSE);
break; break;
case Matrix3: case Matrix3:
fb = (FloatBuffer) uniform.getValue(); fb = (FloatBuffer) uniform.getValue();
assert fb.remaining() == 9; assert fb.remaining() == 9;
gl.getGL2GL3().glUniformMatrix3fv(loc, 1, false, fb); gl.getGL2ES2().glUniformMatrix3fv(loc, 1, false, fb);
break; break;
case Matrix4: case Matrix4:
fb = (FloatBuffer) uniform.getValue(); fb = (FloatBuffer) uniform.getValue();
assert fb.remaining() == 16; assert fb.remaining() == 16;
gl.getGL2GL3().glUniformMatrix4fv(loc, 1, false, fb); gl.getGL2ES2().glUniformMatrix4fv(loc, 1, false, fb);
break; break;
case FloatArray: case FloatArray:
fb = (FloatBuffer) uniform.getValue(); fb = (FloatBuffer) uniform.getValue();
gl.getGL2GL3().glUniform1fv(loc, fb.remaining(), fb); gl.getGL2ES2().glUniform1fv(loc, fb.remaining(), fb);
break; break;
case Vector2Array: case Vector2Array:
fb = (FloatBuffer) uniform.getValue(); fb = (FloatBuffer) uniform.getValue();
gl.getGL2GL3().glUniform2fv(loc, fb.remaining(), fb); gl.getGL2ES2().glUniform2fv(loc, fb.remaining(), fb);
break; break;
case Vector3Array: case Vector3Array:
fb = (FloatBuffer) uniform.getValue(); fb = (FloatBuffer) uniform.getValue();
gl.getGL2GL3().glUniform3fv(loc, fb.remaining(), fb); gl.getGL2ES2().glUniform3fv(loc, fb.remaining(), fb);
break; break;
case Vector4Array: case Vector4Array:
fb = (FloatBuffer) uniform.getValue(); fb = (FloatBuffer) uniform.getValue();
gl.getGL2GL3().glUniform4fv(loc, fb.remaining(), fb); gl.getGL2ES2().glUniform4fv(loc, fb.remaining(), fb);
break; break;
case Matrix4Array: case Matrix4Array:
fb = (FloatBuffer) uniform.getValue(); fb = (FloatBuffer) uniform.getValue();
gl.getGL2GL3().glUniformMatrix4fv(loc, 1, false, fb); gl.getGL2ES2().glUniformMatrix4fv(loc, 1, false, fb);
break; break;
case Int: case Int:
Integer i = (Integer) uniform.getValue(); Integer i = (Integer) uniform.getValue();
gl.getGL2GL3().glUniform1i(loc, i.intValue()); gl.getGL2ES2().glUniform1i(loc, i.intValue());
break; break;
default: default:
throw new UnsupportedOperationException("Unsupported uniform type: " + uniform.getVarType()); throw new UnsupportedOperationException("Unsupported uniform type: " + uniform.getVarType());
@ -944,9 +960,9 @@ public class JoglRenderer implements Renderer {
public int convertShaderType(Shader.ShaderType type) { public int convertShaderType(Shader.ShaderType type) {
switch (type) { switch (type) {
case Fragment: case Fragment:
return GL2.GL_FRAGMENT_SHADER; return GL2ES2.GL_FRAGMENT_SHADER;
case Vertex: case Vertex:
return GL2.GL_VERTEX_SHADER; return GL2ES2.GL_VERTEX_SHADER;
// case Geometry: // case Geometry:
// return ARBGeometryShader4.GL_GEOMETRY_SHADER_ARB; // return ARBGeometryShader4.GL_GEOMETRY_SHADER_ARB;
default: default:
@ -959,7 +975,7 @@ public class JoglRenderer implements Renderer {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
if (id == -1) { if (id == -1) {
// Create id // Create id
id = gl.getGL2GL3().glCreateShader(convertShaderType(source.getType())); id = gl.getGL2ES2().glCreateShader(convertShaderType(source.getType()));
if (id <= 0) { if (id <= 0) {
throw new RendererException("Invalid ID received when trying to create shader."); throw new RendererException("Invalid ID received when trying to create shader.");
} }
@ -1001,10 +1017,10 @@ public class JoglRenderer implements Renderer {
codeBuf.get(array); codeBuf.get(array);
codeBuf.rewind(); codeBuf.rewind();
gl.getGL2GL3().glShaderSource(id, 1, new String[]{new String(array)}, new int[]{array.length}, 0); gl.getGL2ES2().glShaderSource(id, 1, new String[]{new String(array)}, new int[]{array.length}, 0);
gl.getGL2GL3().glCompileShader(id); gl.getGL2ES2().glCompileShader(id);
gl.getGL2GL3().glGetShaderiv(id, GL2.GL_COMPILE_STATUS, intBuf1); gl.getGL2ES2().glGetShaderiv(id, GL2ES2.GL_COMPILE_STATUS, intBuf1);
boolean compiledOK = intBuf1.get(0) == GL.GL_TRUE; boolean compiledOK = intBuf1.get(0) == GL.GL_TRUE;
String infoLog = null; String infoLog = null;
@ -1012,12 +1028,12 @@ public class JoglRenderer implements Renderer {
if (VALIDATE_SHADER || !compiledOK) { if (VALIDATE_SHADER || !compiledOK) {
// even if compile succeeded, check // even if compile succeeded, check
// log for warnings // log for warnings
gl.getGL2GL3().glGetShaderiv(id, GL2.GL_INFO_LOG_LENGTH, intBuf1); gl.getGL2ES2().glGetShaderiv(id, GL2ES2.GL_INFO_LOG_LENGTH, intBuf1);
int length = intBuf1.get(0); int length = intBuf1.get(0);
if (length > 3) { if (length > 3) {
// get infos // get infos
ByteBuffer logBuf = BufferUtils.createByteBuffer(length); ByteBuffer logBuf = BufferUtils.createByteBuffer(length);
gl.getGL2GL3().glGetShaderInfoLog(id, length, null, logBuf); gl.getGL2ES2().glGetShaderInfoLog(id, length, null, logBuf);
byte[] logBytes = new byte[length]; byte[] logBytes = new byte[length];
logBuf.get(logBytes, 0, length); logBuf.get(logBytes, 0, length);
// convert to string, etc // convert to string, etc
@ -1050,7 +1066,7 @@ public class JoglRenderer implements Renderer {
boolean needRegister = false; boolean needRegister = false;
if (id == -1) { if (id == -1) {
// create program // create program
id = gl.getGL2GL3().glCreateProgram(); id = gl.getGL2ES2().glCreateProgram();
if (id == 0) { if (id == 0) {
throw new RendererException("Invalid ID (" + id + ") received when trying to create shader program."); throw new RendererException("Invalid ID (" + id + ") received when trying to create shader program.");
} }
@ -1063,10 +1079,10 @@ public class JoglRenderer implements Renderer {
if (source.isUpdateNeeded()) { if (source.isUpdateNeeded()) {
updateShaderSourceData(source); updateShaderSourceData(source);
} }
gl.getGL2GL3().glAttachShader(id, source.getId()); gl.getGL2ES2().glAttachShader(id, source.getId());
} }
if (caps.contains(Caps.OpenGL30)) { if (caps.contains(Caps.OpenGL30) && gl.isGL2GL3()) {
// Check if GLSL version is 1.5 for shader // Check if GLSL version is 1.5 for shader
gl.getGL2GL3().glBindFragDataLocation(id, 0, "outFragColor"); gl.getGL2GL3().glBindFragDataLocation(id, 0, "outFragColor");
// For MRT // For MRT
@ -1076,20 +1092,20 @@ public class JoglRenderer implements Renderer {
} }
// Link shaders to program // Link shaders to program
gl.getGL2GL3().glLinkProgram(id); gl.getGL2ES2().glLinkProgram(id);
// Check link status // Check link status
gl.getGL2GL3().glGetProgramiv(id, GL2.GL_LINK_STATUS, intBuf1); gl.getGL2ES2().glGetProgramiv(id, GL2ES2.GL_LINK_STATUS, intBuf1);
boolean linkOK = intBuf1.get(0) == GL.GL_TRUE; boolean linkOK = intBuf1.get(0) == GL.GL_TRUE;
String infoLog = null; String infoLog = null;
if (VALIDATE_SHADER || !linkOK) { if (VALIDATE_SHADER || !linkOK) {
gl.getGL2GL3().glGetProgramiv(id, GL2.GL_INFO_LOG_LENGTH, intBuf1); gl.getGL2ES2().glGetProgramiv(id, GL2ES2.GL_INFO_LOG_LENGTH, intBuf1);
int length = intBuf1.get(0); int length = intBuf1.get(0);
if (length > 3) { if (length > 3) {
// get infos // get infos
ByteBuffer logBuf = BufferUtils.createByteBuffer(length); ByteBuffer logBuf = BufferUtils.createByteBuffer(length);
gl.getGL2GL3().glGetProgramInfoLog(id, length, null, logBuf); gl.getGL2ES2().glGetProgramInfoLog(id, length, null, logBuf);
// convert to string, etc // convert to string, etc
byte[] logBytes = new byte[length]; byte[] logBytes = new byte[length];
@ -1147,7 +1163,7 @@ public class JoglRenderer implements Renderer {
} }
source.clearUpdateNeeded(); source.clearUpdateNeeded();
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
gl.getGL2GL3().glDeleteShader(source.getId()); gl.getGL2ES2().glDeleteShader(source.getId());
source.resetObject(); source.resetObject();
} }
@ -1160,12 +1176,12 @@ public class JoglRenderer implements Renderer {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
for (ShaderSource source : shader.getSources()) { for (ShaderSource source : shader.getSources()) {
if (source.getId() != -1) { if (source.getId() != -1) {
gl.getGL2GL3().glDetachShader(shader.getId(), source.getId()); gl.getGL2ES2().glDetachShader(shader.getId(), source.getId());
deleteShaderSource(source); deleteShaderSource(source);
} }
} }
gl.getGL2GL3().glDeleteProgram(shader.getId()); gl.getGL2ES2().glDeleteProgram(shader.getId());
statistics.onDeleteShader(); statistics.onDeleteShader();
shader.resetObject(); shader.resetObject();
} }
@ -1179,7 +1195,7 @@ public class JoglRenderer implements Renderer {
public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth) { public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth) {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
if (gl.isExtensionAvailable("GL_EXT_framebuffer_blit")) { if (gl.isExtensionAvailable("GL_EXT_framebuffer_blit") && gl.isGL2GL3()) {
int srcX0 = 0; int srcX0 = 0;
int srcY0 = 0; int srcY0 = 0;
int srcX1/* = 0*/; int srcX1/* = 0*/;
@ -1210,24 +1226,24 @@ public class JoglRenderer implements Renderer {
} }
if (src == null) { if (src == null) {
gl.glBindFramebuffer(GL2.GL_READ_FRAMEBUFFER, 0); gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, 0);
srcX0 = vpX; srcX0 = vpX;
srcY0 = vpY; srcY0 = vpY;
srcX1 = vpX + vpW; srcX1 = vpX + vpW;
srcY1 = vpY + vpH; srcY1 = vpY + vpH;
} else { } else {
gl.glBindFramebuffer(GL2.GL_READ_FRAMEBUFFER, src.getId()); gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, src.getId());
srcX1 = src.getWidth(); srcX1 = src.getWidth();
srcY1 = src.getHeight(); srcY1 = src.getHeight();
} }
if (dst == null) { if (dst == null) {
gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, 0); gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, 0);
dstX0 = vpX; dstX0 = vpX;
dstY0 = vpY; dstY0 = vpY;
dstX1 = vpX + vpW; dstX1 = vpX + vpW;
dstY1 = vpY + vpH; dstY1 = vpY + vpH;
} else { } else {
gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, dst.getId()); gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, dst.getId());
dstX1 = dst.getWidth(); dstX1 = dst.getWidth();
dstY1 = dst.getHeight(); dstY1 = dst.getHeight();
} }
@ -1238,9 +1254,9 @@ public class JoglRenderer implements Renderer {
gl.getGL2GL3().glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, gl.getGL2GL3().glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
dstX0, dstY0, dstX1, dstY1, mask, dstX0, dstY0, dstX1, dstY1, mask,
GL.GL_NEAREST); GL.GL_NEAREST);
gl.glBindFramebuffer(GL2GL3.GL_FRAMEBUFFER, prevFBO);
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, prevFBO);
try { try {
checkFrameBufferError(); checkFrameBufferError();
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
@ -1264,7 +1280,7 @@ public class JoglRenderer implements Renderer {
return "GL_BACK"; return "GL_BACK";
default: default:
if (buffer >= GL.GL_COLOR_ATTACHMENT0 if (buffer >= GL.GL_COLOR_ATTACHMENT0
&& buffer <= GL2.GL_COLOR_ATTACHMENT15) { && buffer <= GL2ES2.GL_COLOR_ATTACHMENT15) {
return "GL_COLOR_ATTACHMENT" return "GL_COLOR_ATTACHMENT"
+ (buffer - GL.GL_COLOR_ATTACHMENT0); + (buffer - GL.GL_COLOR_ATTACHMENT0);
} else { } else {
@ -1281,11 +1297,11 @@ public class JoglRenderer implements Renderer {
int attachment = convertAttachmentSlot(rb.getSlot()); int attachment = convertAttachmentSlot(rb.getSlot());
gl.glGetFramebufferAttachmentParameteriv(GL2.GL_DRAW_FRAMEBUFFER, gl.glGetFramebufferAttachmentParameteriv(GL2GL3.GL_DRAW_FRAMEBUFFER,
attachment, attachment,
GL.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, intBuf16); GL.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, intBuf16);
int type = intBuf16.get(0); int type = intBuf16.get(0);
gl.glGetFramebufferAttachmentParameteriv(GL2.GL_DRAW_FRAMEBUFFER, gl.glGetFramebufferAttachmentParameteriv(GL2GL3.GL_DRAW_FRAMEBUFFER,
attachment, attachment,
GL.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, intBuf16); GL.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, intBuf16);
int rbName = intBuf16.get(0); int rbName = intBuf16.get(0);
@ -1297,7 +1313,7 @@ public class JoglRenderer implements Renderer {
case GL.GL_TEXTURE: case GL.GL_TEXTURE:
System.out.println("Type: Texture"); System.out.println("Type: Texture");
break; break;
case GL2.GL_RENDERBUFFER: case GL.GL_RENDERBUFFER:
System.out.println("Type: Buffer"); System.out.println("Type: Buffer");
System.out.println("RB ID: " + rbName); System.out.println("RB ID: " + rbName);
break; break;
@ -1310,17 +1326,17 @@ public class JoglRenderer implements Renderer {
private void printRealFrameBufferInfo(FrameBuffer fb) { private void printRealFrameBufferInfo(FrameBuffer fb) {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
final byte[] param = new byte[1]; final byte[] param = new byte[1];
gl.glGetBooleanv(GL2.GL_DOUBLEBUFFER, param, 0); gl.glGetBooleanv(GL2GL3.GL_DOUBLEBUFFER, param, 0);
boolean doubleBuffer = param[0] != (byte) 0x00; boolean doubleBuffer = param[0] != (byte) 0x00;
gl.glGetIntegerv(GL2.GL_DRAW_BUFFER, intBuf16); gl.glGetIntegerv(GL2GL3.GL_DRAW_BUFFER, intBuf16);
String drawBuf = getTargetBufferName(intBuf16.get(0)); String drawBuf = getTargetBufferName(intBuf16.get(0));
gl.glGetIntegerv(GL2.GL_READ_BUFFER, intBuf16); gl.glGetIntegerv(GL2GL3.GL_READ_BUFFER, intBuf16);
String readBuf = getTargetBufferName(intBuf16.get(0)); String readBuf = getTargetBufferName(intBuf16.get(0));
int fbId = fb.getId(); int fbId = fb.getId();
gl.glGetIntegerv(GL2.GL_DRAW_FRAMEBUFFER_BINDING, intBuf16); gl.glGetIntegerv(GL2GL3.GL_DRAW_FRAMEBUFFER_BINDING, intBuf16);
int curDrawBinding = intBuf16.get(0); int curDrawBinding = intBuf16.get(0);
gl.glGetIntegerv(GL2.GL_READ_FRAMEBUFFER_BINDING, intBuf16); gl.glGetIntegerv(GL2GL3.GL_READ_FRAMEBUFFER_BINDING, intBuf16);
int curReadBinding = intBuf16.get(0); int curReadBinding = intBuf16.get(0);
System.out.println("=== OpenGL FBO State ==="); System.out.println("=== OpenGL FBO State ===");
@ -1333,7 +1349,7 @@ public class JoglRenderer implements Renderer {
System.out.println("Read buffer: " + readBuf); System.out.println("Read buffer: " + readBuf);
if (context.boundFBO != fbId) { if (context.boundFBO != fbId) {
gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, fbId); gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, fbId);
context.boundFBO = fbId; context.boundFBO = fbId;
} }
@ -1400,7 +1416,7 @@ public class JoglRenderer implements Renderer {
TextureUtil.GLImageFormat glFmt = TextureUtil.getImageFormatWithError(rb.getFormat()); TextureUtil.GLImageFormat glFmt = TextureUtil.getImageFormatWithError(rb.getFormat());
if (fb.getSamples() > 1 && gl.isExtensionAvailable("GL_EXT_framebuffer_multisample") if (fb.getSamples() > 1 && gl.isExtensionAvailable("GL_EXT_framebuffer_multisample")
/*&& gl.isFunctionAvailable("glRenderbufferStorageMultisample")*/) { && gl.isGL2GL3()/*&& gl.isFunctionAvailable("glRenderbufferStorageMultisample")*/) {
int samples = fb.getSamples(); int samples = fb.getSamples();
if (maxFBOSamples < samples) { if (maxFBOSamples < samples) {
samples = maxFBOSamples; samples = maxFBOSamples;
@ -1505,11 +1521,13 @@ public class JoglRenderer implements Renderer {
Vector2f[] samplePositions = new Vector2f[fb.getSamples()]; Vector2f[] samplePositions = new Vector2f[fb.getSamples()];
FloatBuffer samplePos = BufferUtils.createFloatBuffer(2); FloatBuffer samplePos = BufferUtils.createFloatBuffer(2);
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
for (int i = 0; i < samplePositions.length; i++) { if (gl.isGL2GL3()) {
gl.getGL2GL3().glGetMultisamplefv(GL2.GL_SAMPLE_POSITION, i, samplePos); for (int i = 0; i < samplePositions.length; i++) {
samplePos.clear(); gl.getGL2GL3().glGetMultisamplefv(GL2GL3.GL_SAMPLE_POSITION, i, samplePos);
samplePositions[i] = new Vector2f(samplePos.get(0) - 0.5f, samplePos.clear();
samplePos.get(1) - 0.5f); samplePositions[i] = new Vector2f(samplePos.get(0) - 0.5f,
samplePos.get(1) - 0.5f);
}
} }
return samplePositions; return samplePositions;
} }
@ -1557,11 +1575,15 @@ public class JoglRenderer implements Renderer {
} }
// select back buffer // select back buffer
if (context.boundDrawBuf != -1) { if (context.boundDrawBuf != -1) {
gl.getGL2GL3().glDrawBuffer(initialDrawBuf); if (gl.isGL2GL3()) {
gl.getGL2GL3().glDrawBuffer(initialDrawBuf);
}
context.boundDrawBuf = -1; context.boundDrawBuf = -1;
} }
if (context.boundReadBuf != -1) { if (context.boundReadBuf != -1) {
gl.getGL2GL3().glReadBuffer(initialReadBuf); if (gl.isGL2GL3()) {
gl.getGL2GL3().glReadBuffer(initialReadBuf);
}
context.boundReadBuf = -1; context.boundReadBuf = -1;
} }
@ -1591,11 +1613,15 @@ public class JoglRenderer implements Renderer {
// make sure to select NONE as draw buf // make sure to select NONE as draw buf
// no color buffer attached. select NONE // no color buffer attached. select NONE
if (context.boundDrawBuf != -2) { if (context.boundDrawBuf != -2) {
gl.getGL2GL3().glDrawBuffer(GL.GL_NONE); if (gl.isGL2GL3()) {
gl.getGL2GL3().glDrawBuffer(GL.GL_NONE);
}
context.boundDrawBuf = -2; context.boundDrawBuf = -2;
} }
if (context.boundReadBuf != -2) { if (context.boundReadBuf != -2) {
gl.getGL2GL3().glReadBuffer(GL.GL_NONE); if (gl.isGL2GL3()) {
gl.getGL2GL3().glReadBuffer(GL.GL_NONE);
}
context.boundReadBuf = -2; context.boundReadBuf = -2;
} }
} else { } else {
@ -1618,14 +1644,18 @@ public class JoglRenderer implements Renderer {
} }
intBuf16.flip(); intBuf16.flip();
gl.getGL2GL3().glDrawBuffers(intBuf16.limit(), intBuf16); if (gl.isGL2GL3()) {
gl.getGL2GL3().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()) {
gl.getGL2GL3().glDrawBuffer(GL.GL_COLOR_ATTACHMENT0 + rb.getSlot()); if (gl.isGL2GL3()) {
gl.getGL2GL3().glDrawBuffer(GL.GL_COLOR_ATTACHMENT0 + rb.getSlot());
}
context.boundDrawBuf = rb.getSlot(); context.boundDrawBuf = rb.getSlot();
} }
} }
@ -1656,7 +1686,9 @@ public class JoglRenderer implements Renderer {
setFrameBuffer(fb); setFrameBuffer(fb);
if (context.boundReadBuf != rb.getSlot()) { if (context.boundReadBuf != rb.getSlot()) {
gl.getGL2GL3().glReadBuffer(GL.GL_COLOR_ATTACHMENT0 + rb.getSlot()); if (gl.isGL2GL3()) {
gl.getGL2GL3().glReadBuffer(GL.GL_COLOR_ATTACHMENT0 + rb.getSlot());
}
context.boundReadBuf = rb.getSlot(); context.boundReadBuf = rb.getSlot();
} }
} else { } else {
@ -1702,18 +1734,18 @@ public class JoglRenderer implements Renderer {
switch (type) { switch (type) {
case TwoDimensional: case TwoDimensional:
if (samples > 1) { if (samples > 1) {
return GL2.GL_TEXTURE_2D_MULTISAMPLE; return GL2GL3.GL_TEXTURE_2D_MULTISAMPLE;
} else { } else {
return GL.GL_TEXTURE_2D; return GL.GL_TEXTURE_2D;
} }
case TwoDimensionalArray: case TwoDimensionalArray:
if (samples > 1) { if (samples > 1) {
return GL2.GL_TEXTURE_2D_MULTISAMPLE_ARRAY; return GL2GL3.GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
} else { } else {
return GL2.GL_TEXTURE_2D_ARRAY; return GL.GL_TEXTURE_2D_ARRAY;
} }
case ThreeDimensional: case ThreeDimensional:
return GL2.GL_TEXTURE_3D; return GL2ES2.GL_TEXTURE_3D;
case CubeMap: case CubeMap:
if (face < 0) { if (face < 0) {
return GL.GL_TEXTURE_CUBE_MAP; return GL.GL_TEXTURE_CUBE_MAP;
@ -1801,13 +1833,13 @@ public class JoglRenderer implements Renderer {
switch (tex.getType()) { switch (tex.getType()) {
case ThreeDimensional: case ThreeDimensional:
case CubeMap: // cubemaps use 3D coords case CubeMap: // cubemaps use 3D coords
gl.glTexParameteri(target, GL2.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R))); gl.glTexParameteri(target, GL2ES2.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
case TwoDimensional: case TwoDimensional:
case TwoDimensionalArray: case TwoDimensionalArray:
gl.glTexParameteri(target, GL2.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T))); gl.glTexParameteri(target, GL2ES2.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));
// fall down here is intentional.. // fall down here is intentional..
// case OneDimensional: // case OneDimensional:
gl.glTexParameteri(target, GL2.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S))); gl.glTexParameteri(target, GL2ES2.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
break; break;
default: default:
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType()); throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
@ -1816,16 +1848,16 @@ public class JoglRenderer implements Renderer {
if (tex.isNeedCompareModeUpdate()) { if (tex.isNeedCompareModeUpdate()) {
// R to Texture compare mode // R to Texture compare mode
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) { if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE); gl.glTexParameteri(target, GL2ES2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE);
gl.glTexParameteri(target, GL2.GL_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY); gl.glTexParameteri(target, GL2.GL_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY);
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) { if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL); gl.glTexParameteri(target, GL2ES2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
} else { } else {
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL); gl.glTexParameteri(target, GL2ES2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
} }
} else { } else {
//restoring default value //restoring default value
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_NONE); gl.glTexParameteri(target, GL2ES2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
} }
tex.compareModeUpdated(); tex.compareModeUpdated();
} }
@ -1869,14 +1901,18 @@ public class JoglRenderer implements Renderer {
// No pregenerated mips available, // No pregenerated mips available,
// generate from base level if required // generate from base level if required
if (!gl.isExtensionAvailable("GL_VERSION_3_0")) { if (!gl.isExtensionAvailable("GL_VERSION_3_0")) {
gl.glTexParameteri(target, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE); if (gl.isGL2ES1()) {
gl.glTexParameteri(target, GL2ES1.GL_GENERATE_MIPMAP, GL.GL_TRUE);
}
img.setMipmapsGenerated(true); img.setMipmapsGenerated(true);
} }
} else { } else {
// Image already has mipmaps or no mipmap generation desired. // Image already has mipmaps or no mipmap generation desired.
// glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0 ); // glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0 );
if (img.getMipMapSizes() != null) { if (img.getMipMapSizes() != null) {
gl.glTexParameteri(target, GL2.GL_TEXTURE_MAX_LEVEL, img.getMipMapSizes().length - 1); if (gl.isGL2GL3()) {
gl.glTexParameteri(target, GL2GL3.GL_TEXTURE_MAX_LEVEL, img.getMipMapSizes().length - 1);
}
} }
} }
@ -2055,7 +2091,7 @@ public class JoglRenderer implements Renderer {
case UnsignedShort: case UnsignedShort:
return GL.GL_UNSIGNED_SHORT; return GL.GL_UNSIGNED_SHORT;
case Int: case Int:
return GL2.GL_INT; return GL2ES2.GL_INT;
case UnsignedInt: case UnsignedInt:
return GL.GL_UNSIGNED_INT; return GL.GL_UNSIGNED_INT;
// case Half: // case Half:
@ -2064,7 +2100,7 @@ public class JoglRenderer implements Renderer {
case Float: case Float:
return GL.GL_FLOAT; return GL.GL_FLOAT;
case Double: case Double:
return GL2.GL_DOUBLE; return GL2GL3.GL_DOUBLE;
default: default:
throw new UnsupportedOperationException("Unknown buffer format."); throw new UnsupportedOperationException("Unknown buffer format.");
@ -2142,7 +2178,7 @@ public class JoglRenderer implements Renderer {
for (int i = 0; i < attribList.oldLen; i++) { for (int i = 0; i < attribList.oldLen; i++) {
int idx = attribList.oldList[i]; int idx = attribList.oldList[i];
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
gl.getGL2GL3().glDisableVertexAttribArray(idx); gl.getGL2ES2().glDisableVertexAttribArray(idx);
context.boundAttribs[idx] = null; context.boundAttribs[idx] = null;
} }
context.attribIndexList.copyNewToOld(); context.attribIndexList.copyNewToOld();
@ -2165,7 +2201,7 @@ public class JoglRenderer implements Renderer {
stringBuf.setLength(0); stringBuf.setLength(0);
// JOGL 2.0 doesn't need a null terminated string // JOGL 2.0 doesn't need a null terminated string
stringBuf.append("in").append(vb.getBufferType().name()); stringBuf.append("in").append(vb.getBufferType().name());
loc = gl.getGL2GL3().glGetAttribLocation(programId, stringBuf.toString()); loc = gl.getGL2ES2().glGetAttribLocation(programId, stringBuf.toString());
// not really the name of it in the shader (inPosition\0) but // not really the name of it in the shader (inPosition\0) but
// the internal name of the enum (Position). // the internal name of the enum (Position).
@ -2183,7 +2219,7 @@ public class JoglRenderer implements Renderer {
VertexBuffer[] attribs = context.boundAttribs; VertexBuffer[] attribs = context.boundAttribs;
if (!context.attribIndexList.moveToNew(loc)) { if (!context.attribIndexList.moveToNew(loc)) {
gl.getGL2GL3().glEnableVertexAttribArray(loc); gl.getGL2ES2().glEnableVertexAttribArray(loc);
//System.out.println("Enabled ATTRIB IDX: "+loc); //System.out.println("Enabled ATTRIB IDX: "+loc);
} }
if (attribs[loc] != vb) { if (attribs[loc] != vb) {
@ -2198,7 +2234,7 @@ public class JoglRenderer implements Renderer {
//statistics.onVertexBufferUse(vb, false); //statistics.onVertexBufferUse(vb, false);
} }
gl.getGL2GL3().glVertexAttribPointer(loc, gl.getGL2ES2().glVertexAttribPointer(loc,
vb.getNumComponents(), vb.getNumComponents(),
convertFormat(vb.getFormat()), convertFormat(vb.getFormat()),
vb.isNormalized(), vb.isNormalized(),
@ -2219,8 +2255,10 @@ public class JoglRenderer implements Renderer {
public void drawTriangleArray(Mesh.Mode mode, int count, int vertCount) { public void drawTriangleArray(Mesh.Mode mode, int count, int vertCount) {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
if (count > 1) { if (count > 1) {
gl.getGL2GL3().glDrawArraysInstanced(convertElementMode(mode), 0, if (gl.isGL2GL3()) {
gl.getGL2GL3().glDrawArraysInstanced(convertElementMode(mode), 0,
vertCount, count); vertCount, count);
}
} else { } else {
gl.glDrawArrays(convertElementMode(mode), 0, vertCount); gl.glDrawArrays(convertElementMode(mode), 0, vertCount);
} }
@ -2239,74 +2277,78 @@ public class JoglRenderer implements Renderer {
assert bufId != -1; assert bufId != -1;
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
if (context.boundElementArrayVBO != bufId) { if (gl.isGL2GL3()) {
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, bufId); if (context.boundElementArrayVBO != bufId) {
context.boundElementArrayVBO = bufId; gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, bufId);
//statistics.onVertexBufferUse(indexBuf, true); context.boundElementArrayVBO = bufId;
} else { //statistics.onVertexBufferUse(indexBuf, true);
//statistics.onVertexBufferUse(indexBuf, true); } else {
} //statistics.onVertexBufferUse(indexBuf, true);
}
int vertCount = mesh.getVertexCount();
boolean useInstancing = count > 1 && caps.contains(Caps.MeshInstancing); int vertCount = mesh.getVertexCount();
boolean useInstancing = count > 1 && caps.contains(Caps.MeshInstancing);
if (mesh.getMode() == Mode.Hybrid) {
int[] modeStart = mesh.getModeStart(); if (mesh.getMode() == Mode.Hybrid) {
int[] elementLengths = mesh.getElementLengths(); int[] modeStart = mesh.getModeStart();
int[] elementLengths = mesh.getElementLengths();
int elMode = convertElementMode(Mode.Triangles);
int fmt = convertFormat(indexBuf.getFormat()); int elMode = convertElementMode(Mode.Triangles);
int elSize = indexBuf.getFormat().getComponentSize(); int fmt = convertFormat(indexBuf.getFormat());
int listStart = modeStart[0]; int elSize = indexBuf.getFormat().getComponentSize();
int stripStart = modeStart[1]; int listStart = modeStart[0];
int fanStart = modeStart[2]; int stripStart = modeStart[1];
int curOffset = 0; int fanStart = modeStart[2];
for (int i = 0; i < elementLengths.length; i++) { int curOffset = 0;
if (i == stripStart) { for (int i = 0; i < elementLengths.length; i++) {
elMode = convertElementMode(Mode.TriangleStrip); if (i == stripStart) {
} else if (i == fanStart) { elMode = convertElementMode(Mode.TriangleStrip);
elMode = convertElementMode(Mode.TriangleStrip); } else if (i == fanStart) {
} elMode = convertElementMode(Mode.TriangleStrip);
int elementLength = elementLengths[i]; }
int elementLength = elementLengths[i];
if (useInstancing) {
indexBuf.getData().position(curOffset);
indexBuf.getData().limit(curOffset + elementLength);
gl.getGL2GL3().glDrawElementsInstanced(elMode,
elementLength,
fmt,
indexBuf.getData(),
count);
} else {
gl.getGL2GL3().glDrawRangeElements(elMode,
0,
vertCount,
elementLength,
fmt,
curOffset);
}
//FIXME check whether elSize is required
curOffset += elementLength/* * elSize*/;
}
} else {
if (useInstancing) { if (useInstancing) {
gl.getGL2GL3().glDrawElementsInstanced(convertElementMode(mesh.getMode()),
indexBuf.getData().position(curOffset); indexBuf.getData().limit(),
indexBuf.getData().limit(curOffset + elementLength); convertFormat(indexBuf.getFormat()),
gl.getGL2GL3().glDrawElementsInstanced(elMode,
elementLength,
fmt,
indexBuf.getData(), indexBuf.getData(),
count); count);
} else { } else {
gl.getGL2GL3().glDrawRangeElements(elMode, gl.getGL2GL3().glDrawRangeElements(convertElementMode(mesh.getMode()),
0, 0,
vertCount, vertCount,
elementLength, indexBuf.getData().limit(),
fmt, convertFormat(indexBuf.getFormat()),
curOffset); 0);
} }
//FIXME check whether elSize is required
curOffset += elementLength/* * elSize*/;
} }
} else { } else {
if (useInstancing) { //FIXME: ES impl
gl.getGL2GL3().glDrawElementsInstanced(convertElementMode(mesh.getMode()),
indexBuf.getData().limit(),
convertFormat(indexBuf.getFormat()),
indexBuf.getData(),
count);
} else {
gl.getGL2GL3().glDrawRangeElements(convertElementMode(mesh.getMode()),
0,
vertCount,
indexBuf.getData().limit(),
convertFormat(indexBuf.getFormat()),
0);
}
} }
} }
@ -2339,13 +2381,17 @@ public class JoglRenderer implements Renderer {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
if (id == -1) { if (id == -1) {
IntBuffer temp = intBuf1; IntBuffer temp = intBuf1;
gl.getGL2GL3().glGenVertexArrays(1, temp); if (gl.isGL2GL3()) {
gl.getGL2GL3().glGenVertexArrays(1, temp);
}
id = temp.get(0); id = temp.get(0);
mesh.setId(id); mesh.setId(id);
} }
if (context.boundVertexArray != id) { if (context.boundVertexArray != id) {
gl.getGL2GL3().glBindVertexArray(id); if (gl.isGL2GL3()) {
gl.getGL2GL3().glBindVertexArray(id);
}
context.boundVertexArray = id; context.boundVertexArray = id;
} }
@ -2380,7 +2426,9 @@ public class JoglRenderer implements Renderer {
if (context.boundVertexArray != mesh.getId()) { if (context.boundVertexArray != mesh.getId()) {
GL gl = GLContext.getCurrentGL(); GL gl = GLContext.getCurrentGL();
gl.getGL2GL3().glBindVertexArray(mesh.getId()); if (gl.isGL2GL3()) {
gl.getGL2GL3().glBindVertexArray(mesh.getId());
}
context.boundVertexArray = mesh.getId(); context.boundVertexArray = mesh.getId();
} }
@ -2457,14 +2505,20 @@ public class JoglRenderer implements Renderer {
gl.glActiveTexture(GL.GL_TEXTURE0); gl.glActiveTexture(GL.GL_TEXTURE0);
context.boundTextureUnit = 0; context.boundTextureUnit = 0;
} }
gl.glDisable(GL2.GL_POINT_SPRITE); if (gl.isGL2ES1()) {
gl.glDisable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE); gl.glDisable(GL2ES1.GL_POINT_SPRITE);
}
if (gl.isGL2GL3()) {
gl.glDisable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
}
context.pointSprite = false; context.pointSprite = false;
} }
} }
if (context.pointSize != mesh.getPointSize()) { if (context.pointSize != mesh.getPointSize()) {
gl.getGL2GL3().glPointSize(mesh.getPointSize()); if (gl.isGL2GL3()) {
gl.getGL2GL3().glPointSize(mesh.getPointSize());
}
context.pointSize = mesh.getPointSize(); context.pointSize = mesh.getPointSize();
} }
if (context.lineWidth != mesh.getLineWidth()) { if (context.lineWidth != mesh.getLineWidth()) {

Loading…
Cancel
Save