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
This commit is contained in:
parent
5d24544589
commit
b242f66c5a
@ -62,6 +62,7 @@ import java.util.EnumSet;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.media.opengl.*;
|
||||
import javax.media.opengl.fixedfunc.GLLightingFunc;
|
||||
import jme3tools.converters.MipMapGenerator;
|
||||
|
||||
public class JoglGL1Renderer implements GL1Renderer {
|
||||
@ -120,16 +121,16 @@ public class JoglGL1Renderer implements GL1Renderer {
|
||||
}
|
||||
|
||||
// Default values for certain GL state.
|
||||
gl.getGL2().glShadeModel(GL2.GL_SMOOTH);
|
||||
gl.getGL2().glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE);
|
||||
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
|
||||
gl.getGL2ES1().glShadeModel(GLLightingFunc.GL_SMOOTH);
|
||||
gl.getGL2().glColorMaterial(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_DIFFUSE);
|
||||
gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
|
||||
|
||||
// Enable rescaling/normaling of normal vectors.
|
||||
// Fixes lighting issues with scaled models.
|
||||
if (gl12){
|
||||
gl.glEnable(GL2.GL_RESCALE_NORMAL);
|
||||
gl.glEnable(GL2ES1.GL_RESCALE_NORMAL);
|
||||
}else{
|
||||
gl.glEnable(GL2.GL_NORMALIZE);
|
||||
gl.glEnable(GLLightingFunc.GL_NORMALIZE);
|
||||
}
|
||||
|
||||
if (gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two")) {
|
||||
@ -140,7 +141,7 @@ public class JoglGL1Renderer implements GL1Renderer {
|
||||
+ "Some features might not work.");
|
||||
}
|
||||
|
||||
gl.glGetIntegerv(GL2.GL_MAX_LIGHTS, ib1);
|
||||
gl.glGetIntegerv(GL2ES1.GL_MAX_LIGHTS, ib1);
|
||||
maxLights = ib1.get(0);
|
||||
|
||||
gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, ib1);
|
||||
@ -167,7 +168,7 @@ public class JoglGL1Renderer implements GL1Renderer {
|
||||
|
||||
public void setDepthRange(float start, float end) {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
gl.getGL2().glDepthRange(start, end);
|
||||
gl.getGL2ES2().glDepthRange(start, end);
|
||||
}
|
||||
|
||||
public void clearBuffers(boolean color, boolean depth, boolean stencil) {
|
||||
@ -222,15 +223,15 @@ public class JoglGL1Renderer implements GL1Renderer {
|
||||
private void applyFixedFuncBindings(boolean forLighting){
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
if (forLighting) {
|
||||
gl.getGL2().glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, context.shininess);
|
||||
setMaterialColor(GL2.GL_AMBIENT, context.ambient, ColorRGBA.DarkGray);
|
||||
setMaterialColor(GL2.GL_DIFFUSE, context.diffuse, ColorRGBA.White);
|
||||
setMaterialColor(GL2.GL_SPECULAR, context.specular, ColorRGBA.Black);
|
||||
gl.getGL2().glMaterialf(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SHININESS, context.shininess);
|
||||
setMaterialColor(GLLightingFunc.GL_AMBIENT, context.ambient, ColorRGBA.DarkGray);
|
||||
setMaterialColor(GLLightingFunc.GL_DIFFUSE, context.diffuse, ColorRGBA.White);
|
||||
setMaterialColor(GLLightingFunc.GL_SPECULAR, context.specular, ColorRGBA.Black);
|
||||
|
||||
if (context.useVertexColor) {
|
||||
gl.glEnable(GL2.GL_COLOR_MATERIAL);
|
||||
gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL);
|
||||
} else {
|
||||
gl.glDisable(GL2.GL_COLOR_MATERIAL);
|
||||
gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL);
|
||||
}
|
||||
} else {
|
||||
// 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.NativeObjectManager;
|
||||
import com.jme3.util.SafeArrayList;
|
||||
import com.jogamp.common.nio.Buffers;
|
||||
import java.nio.*;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
@ -72,6 +71,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.media.opengl.GL;
|
||||
import javax.media.opengl.GL2;
|
||||
import javax.media.opengl.GL2ES1;
|
||||
import javax.media.opengl.GL2ES2;
|
||||
import javax.media.opengl.GL2GL3;
|
||||
import javax.media.opengl.GLContext;
|
||||
@ -361,16 +361,16 @@ public class JoglRenderer implements Renderer {
|
||||
if (gl.isExtensionAvailable("GL_ARB_texture_multisample")) {
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
if (maxMRTFBOAttachs > 1) {
|
||||
caps.add(Caps.FrameBufferMRT);
|
||||
@ -407,9 +407,9 @@ public class JoglRenderer implements Renderer {
|
||||
lastFb = null;
|
||||
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
gl.glGetIntegerv(GL2.GL_DRAW_BUFFER, intBuf1);
|
||||
gl.glGetIntegerv(GL2GL3.GL_DRAW_BUFFER, intBuf1);
|
||||
initialDrawBuf = intBuf1.get(0);
|
||||
gl.glGetIntegerv(GL2.GL_READ_BUFFER, intBuf1);
|
||||
gl.glGetIntegerv(GL2GL3.GL_READ_BUFFER, intBuf1);
|
||||
initialReadBuf = intBuf1.get(0);
|
||||
}
|
||||
|
||||
@ -481,9 +481,9 @@ public class JoglRenderer implements Renderer {
|
||||
if (caps.contains(Caps.Multisample)) {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
if (value) {
|
||||
gl.glEnable(GL2.GL_SAMPLE_ALPHA_TO_COVERAGE);
|
||||
gl.glEnable(GL.GL_SAMPLE_ALPHA_TO_COVERAGE);
|
||||
} 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) {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
|
||||
@ -508,11 +512,15 @@ public class JoglRenderer implements Renderer {
|
||||
}
|
||||
|
||||
if (state.isAlphaTest() && context.alphaTestFallOff == 0) {
|
||||
gl.glEnable(GL2.GL_ALPHA_TEST);
|
||||
gl.getGL2().glAlphaFunc(GL.GL_GREATER, state.getAlphaFallOff());
|
||||
gl.glEnable(GL2ES1.GL_ALPHA_TEST);
|
||||
if (gl.isGL2ES1()) {
|
||||
gl.getGL2ES1().glAlphaFunc(GL.GL_GREATER, state.getAlphaFallOff());
|
||||
}
|
||||
context.alphaTestFallOff = state.getAlphaFallOff();
|
||||
} 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;
|
||||
}
|
||||
|
||||
@ -539,8 +547,12 @@ public class JoglRenderer implements Renderer {
|
||||
gl.glActiveTexture(GL.GL_TEXTURE0);
|
||||
context.boundTextureUnit = 0;
|
||||
}
|
||||
gl.glEnable(GL2.GL_POINT_SPRITE);
|
||||
gl.glEnable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
if (gl.isGL2ES1()) {
|
||||
gl.glEnable(GL2ES1.GL_POINT_SPRITE);
|
||||
}
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.glEnable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
}
|
||||
}
|
||||
context.pointSprite = true;
|
||||
} else if (!state.isPointSprite() && context.pointSprite) {
|
||||
@ -549,8 +561,12 @@ public class JoglRenderer implements Renderer {
|
||||
gl.glActiveTexture(GL.GL_TEXTURE0);
|
||||
context.boundTextureUnit = 0;
|
||||
}
|
||||
gl.glDisable(GL2.GL_POINT_SPRITE);
|
||||
gl.glDisable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
if (gl.isGL2ES1()) {
|
||||
gl.glDisable(GL2ES1.GL_POINT_SPRITE);
|
||||
}
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.glDisable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
}
|
||||
context.pointSprite = false;
|
||||
}
|
||||
}
|
||||
@ -667,18 +683,18 @@ public class JoglRenderer implements Renderer {
|
||||
|
||||
if (state.isStencilTest()) {
|
||||
gl.glEnable(GL.GL_STENCIL_TEST);
|
||||
gl.getGL2GL3().glStencilOpSeparate(GL.GL_FRONT,
|
||||
gl.getGL2ES2().glStencilOpSeparate(GL.GL_FRONT,
|
||||
convertStencilOperation(state.getFrontStencilStencilFailOperation()),
|
||||
convertStencilOperation(state.getFrontStencilDepthFailOperation()),
|
||||
convertStencilOperation(state.getFrontStencilDepthPassOperation()));
|
||||
gl.getGL2GL3().glStencilOpSeparate(GL.GL_BACK,
|
||||
gl.getGL2ES2().glStencilOpSeparate(GL.GL_BACK,
|
||||
convertStencilOperation(state.getBackStencilStencilFailOperation()),
|
||||
convertStencilOperation(state.getBackStencilDepthFailOperation()),
|
||||
convertStencilOperation(state.getBackStencilDepthPassOperation()));
|
||||
gl.getGL2GL3().glStencilFuncSeparate(GL.GL_FRONT,
|
||||
gl.getGL2ES2().glStencilFuncSeparate(GL.GL_FRONT,
|
||||
convertTestFunction(state.getFrontStencilFunction()),
|
||||
0, Integer.MAX_VALUE);
|
||||
gl.getGL2GL3().glStencilFuncSeparate(GL.GL_BACK,
|
||||
gl.getGL2ES2().glStencilFuncSeparate(GL.GL_BACK,
|
||||
convertTestFunction(state.getBackStencilFunction()),
|
||||
0, Integer.MAX_VALUE);
|
||||
} else {
|
||||
@ -791,7 +807,7 @@ public class JoglRenderer implements Renderer {
|
||||
protected void updateUniformLocation(Shader shader, Uniform uniform) {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
// 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) {
|
||||
uniform.setLocation(-1);
|
||||
// uniform is not declared in shader
|
||||
@ -806,7 +822,7 @@ public class JoglRenderer implements Renderer {
|
||||
int shaderId = shader.getId();
|
||||
if (context.boundShaderProgram != shaderId) {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
gl.getGL2GL3().glUseProgram(shaderId);
|
||||
gl.getGL2ES2().glUseProgram(shaderId);
|
||||
statistics.onShaderUse(shader, true);
|
||||
boundShader = shader;
|
||||
context.boundShaderProgram = shaderId;
|
||||
@ -850,66 +866,66 @@ public class JoglRenderer implements Renderer {
|
||||
switch (uniform.getVarType()) {
|
||||
case Float:
|
||||
Float f = (Float) uniform.getValue();
|
||||
gl.getGL2GL3().glUniform1f(loc, f.floatValue());
|
||||
gl.getGL2ES2().glUniform1f(loc, f.floatValue());
|
||||
break;
|
||||
case Vector2:
|
||||
Vector2f v2 = (Vector2f) uniform.getValue();
|
||||
gl.getGL2GL3().glUniform2f(loc, v2.getX(), v2.getY());
|
||||
gl.getGL2ES2().glUniform2f(loc, v2.getX(), v2.getY());
|
||||
break;
|
||||
case Vector3:
|
||||
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;
|
||||
case Vector4:
|
||||
Object val = uniform.getValue();
|
||||
if (val instanceof ColorRGBA) {
|
||||
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) {
|
||||
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 {
|
||||
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;
|
||||
case Boolean:
|
||||
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;
|
||||
case Matrix3:
|
||||
fb = (FloatBuffer) uniform.getValue();
|
||||
assert fb.remaining() == 9;
|
||||
gl.getGL2GL3().glUniformMatrix3fv(loc, 1, false, fb);
|
||||
gl.getGL2ES2().glUniformMatrix3fv(loc, 1, false, fb);
|
||||
break;
|
||||
case Matrix4:
|
||||
fb = (FloatBuffer) uniform.getValue();
|
||||
assert fb.remaining() == 16;
|
||||
gl.getGL2GL3().glUniformMatrix4fv(loc, 1, false, fb);
|
||||
gl.getGL2ES2().glUniformMatrix4fv(loc, 1, false, fb);
|
||||
break;
|
||||
case FloatArray:
|
||||
fb = (FloatBuffer) uniform.getValue();
|
||||
gl.getGL2GL3().glUniform1fv(loc, fb.remaining(), fb);
|
||||
gl.getGL2ES2().glUniform1fv(loc, fb.remaining(), fb);
|
||||
break;
|
||||
case Vector2Array:
|
||||
fb = (FloatBuffer) uniform.getValue();
|
||||
gl.getGL2GL3().glUniform2fv(loc, fb.remaining(), fb);
|
||||
gl.getGL2ES2().glUniform2fv(loc, fb.remaining(), fb);
|
||||
break;
|
||||
case Vector3Array:
|
||||
fb = (FloatBuffer) uniform.getValue();
|
||||
gl.getGL2GL3().glUniform3fv(loc, fb.remaining(), fb);
|
||||
gl.getGL2ES2().glUniform3fv(loc, fb.remaining(), fb);
|
||||
break;
|
||||
case Vector4Array:
|
||||
fb = (FloatBuffer) uniform.getValue();
|
||||
gl.getGL2GL3().glUniform4fv(loc, fb.remaining(), fb);
|
||||
gl.getGL2ES2().glUniform4fv(loc, fb.remaining(), fb);
|
||||
break;
|
||||
case Matrix4Array:
|
||||
fb = (FloatBuffer) uniform.getValue();
|
||||
gl.getGL2GL3().glUniformMatrix4fv(loc, 1, false, fb);
|
||||
gl.getGL2ES2().glUniformMatrix4fv(loc, 1, false, fb);
|
||||
break;
|
||||
case Int:
|
||||
Integer i = (Integer) uniform.getValue();
|
||||
gl.getGL2GL3().glUniform1i(loc, i.intValue());
|
||||
gl.getGL2ES2().glUniform1i(loc, i.intValue());
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unsupported uniform type: " + uniform.getVarType());
|
||||
@ -944,9 +960,9 @@ public class JoglRenderer implements Renderer {
|
||||
public int convertShaderType(Shader.ShaderType type) {
|
||||
switch (type) {
|
||||
case Fragment:
|
||||
return GL2.GL_FRAGMENT_SHADER;
|
||||
return GL2ES2.GL_FRAGMENT_SHADER;
|
||||
case Vertex:
|
||||
return GL2.GL_VERTEX_SHADER;
|
||||
return GL2ES2.GL_VERTEX_SHADER;
|
||||
// case Geometry:
|
||||
// return ARBGeometryShader4.GL_GEOMETRY_SHADER_ARB;
|
||||
default:
|
||||
@ -959,7 +975,7 @@ public class JoglRenderer implements Renderer {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
if (id == -1) {
|
||||
// Create id
|
||||
id = gl.getGL2GL3().glCreateShader(convertShaderType(source.getType()));
|
||||
id = gl.getGL2ES2().glCreateShader(convertShaderType(source.getType()));
|
||||
if (id <= 0) {
|
||||
throw new RendererException("Invalid ID received when trying to create shader.");
|
||||
}
|
||||
@ -1001,10 +1017,10 @@ public class JoglRenderer implements Renderer {
|
||||
codeBuf.get(array);
|
||||
codeBuf.rewind();
|
||||
|
||||
gl.getGL2GL3().glShaderSource(id, 1, new String[]{new String(array)}, new int[]{array.length}, 0);
|
||||
gl.getGL2GL3().glCompileShader(id);
|
||||
gl.getGL2ES2().glShaderSource(id, 1, new String[]{new String(array)}, new int[]{array.length}, 0);
|
||||
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;
|
||||
String infoLog = null;
|
||||
@ -1012,12 +1028,12 @@ public class JoglRenderer implements Renderer {
|
||||
if (VALIDATE_SHADER || !compiledOK) {
|
||||
// even if compile succeeded, check
|
||||
// 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);
|
||||
if (length > 3) {
|
||||
// get infos
|
||||
ByteBuffer logBuf = BufferUtils.createByteBuffer(length);
|
||||
gl.getGL2GL3().glGetShaderInfoLog(id, length, null, logBuf);
|
||||
gl.getGL2ES2().glGetShaderInfoLog(id, length, null, logBuf);
|
||||
byte[] logBytes = new byte[length];
|
||||
logBuf.get(logBytes, 0, length);
|
||||
// convert to string, etc
|
||||
@ -1050,7 +1066,7 @@ public class JoglRenderer implements Renderer {
|
||||
boolean needRegister = false;
|
||||
if (id == -1) {
|
||||
// create program
|
||||
id = gl.getGL2GL3().glCreateProgram();
|
||||
id = gl.getGL2ES2().glCreateProgram();
|
||||
if (id == 0) {
|
||||
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()) {
|
||||
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
|
||||
gl.getGL2GL3().glBindFragDataLocation(id, 0, "outFragColor");
|
||||
// For MRT
|
||||
@ -1076,20 +1092,20 @@ public class JoglRenderer implements Renderer {
|
||||
}
|
||||
|
||||
// Link shaders to program
|
||||
gl.getGL2GL3().glLinkProgram(id);
|
||||
gl.getGL2ES2().glLinkProgram(id);
|
||||
|
||||
// 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;
|
||||
String infoLog = null;
|
||||
|
||||
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);
|
||||
if (length > 3) {
|
||||
// get infos
|
||||
ByteBuffer logBuf = BufferUtils.createByteBuffer(length);
|
||||
gl.getGL2GL3().glGetProgramInfoLog(id, length, null, logBuf);
|
||||
gl.getGL2ES2().glGetProgramInfoLog(id, length, null, logBuf);
|
||||
|
||||
// convert to string, etc
|
||||
byte[] logBytes = new byte[length];
|
||||
@ -1147,7 +1163,7 @@ public class JoglRenderer implements Renderer {
|
||||
}
|
||||
source.clearUpdateNeeded();
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
gl.getGL2GL3().glDeleteShader(source.getId());
|
||||
gl.getGL2ES2().glDeleteShader(source.getId());
|
||||
source.resetObject();
|
||||
}
|
||||
|
||||
@ -1160,12 +1176,12 @@ public class JoglRenderer implements Renderer {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
for (ShaderSource source : shader.getSources()) {
|
||||
if (source.getId() != -1) {
|
||||
gl.getGL2GL3().glDetachShader(shader.getId(), source.getId());
|
||||
gl.getGL2ES2().glDetachShader(shader.getId(), source.getId());
|
||||
deleteShaderSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
gl.getGL2GL3().glDeleteProgram(shader.getId());
|
||||
gl.getGL2ES2().glDeleteProgram(shader.getId());
|
||||
statistics.onDeleteShader();
|
||||
shader.resetObject();
|
||||
}
|
||||
@ -1179,7 +1195,7 @@ public class JoglRenderer implements Renderer {
|
||||
|
||||
public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth) {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
if (gl.isExtensionAvailable("GL_EXT_framebuffer_blit")) {
|
||||
if (gl.isExtensionAvailable("GL_EXT_framebuffer_blit") && gl.isGL2GL3()) {
|
||||
int srcX0 = 0;
|
||||
int srcY0 = 0;
|
||||
int srcX1/* = 0*/;
|
||||
@ -1210,24 +1226,24 @@ public class JoglRenderer implements Renderer {
|
||||
}
|
||||
|
||||
if (src == null) {
|
||||
gl.glBindFramebuffer(GL2.GL_READ_FRAMEBUFFER, 0);
|
||||
gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, 0);
|
||||
srcX0 = vpX;
|
||||
srcY0 = vpY;
|
||||
srcX1 = vpX + vpW;
|
||||
srcY1 = vpY + vpH;
|
||||
} else {
|
||||
gl.glBindFramebuffer(GL2.GL_READ_FRAMEBUFFER, src.getId());
|
||||
gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, src.getId());
|
||||
srcX1 = src.getWidth();
|
||||
srcY1 = src.getHeight();
|
||||
}
|
||||
if (dst == null) {
|
||||
gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, 0);
|
||||
gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, 0);
|
||||
dstX0 = vpX;
|
||||
dstY0 = vpY;
|
||||
dstX1 = vpX + vpW;
|
||||
dstY1 = vpY + vpH;
|
||||
} else {
|
||||
gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, dst.getId());
|
||||
gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, dst.getId());
|
||||
dstX1 = dst.getWidth();
|
||||
dstY1 = dst.getHeight();
|
||||
}
|
||||
@ -1238,9 +1254,9 @@ public class JoglRenderer implements Renderer {
|
||||
gl.getGL2GL3().glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
|
||||
dstX0, dstY0, dstX1, dstY1, mask,
|
||||
GL.GL_NEAREST);
|
||||
gl.glBindFramebuffer(GL2GL3.GL_FRAMEBUFFER, prevFBO);
|
||||
|
||||
|
||||
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, prevFBO);
|
||||
|
||||
try {
|
||||
checkFrameBufferError();
|
||||
} catch (IllegalStateException ex) {
|
||||
@ -1264,7 +1280,7 @@ public class JoglRenderer implements Renderer {
|
||||
return "GL_BACK";
|
||||
default:
|
||||
if (buffer >= GL.GL_COLOR_ATTACHMENT0
|
||||
&& buffer <= GL2.GL_COLOR_ATTACHMENT15) {
|
||||
&& buffer <= GL2ES2.GL_COLOR_ATTACHMENT15) {
|
||||
return "GL_COLOR_ATTACHMENT"
|
||||
+ (buffer - GL.GL_COLOR_ATTACHMENT0);
|
||||
} else {
|
||||
@ -1281,11 +1297,11 @@ public class JoglRenderer implements Renderer {
|
||||
|
||||
int attachment = convertAttachmentSlot(rb.getSlot());
|
||||
|
||||
gl.glGetFramebufferAttachmentParameteriv(GL2.GL_DRAW_FRAMEBUFFER,
|
||||
gl.glGetFramebufferAttachmentParameteriv(GL2GL3.GL_DRAW_FRAMEBUFFER,
|
||||
attachment,
|
||||
GL.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, intBuf16);
|
||||
int type = intBuf16.get(0);
|
||||
gl.glGetFramebufferAttachmentParameteriv(GL2.GL_DRAW_FRAMEBUFFER,
|
||||
gl.glGetFramebufferAttachmentParameteriv(GL2GL3.GL_DRAW_FRAMEBUFFER,
|
||||
attachment,
|
||||
GL.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, intBuf16);
|
||||
int rbName = intBuf16.get(0);
|
||||
@ -1297,7 +1313,7 @@ public class JoglRenderer implements Renderer {
|
||||
case GL.GL_TEXTURE:
|
||||
System.out.println("Type: Texture");
|
||||
break;
|
||||
case GL2.GL_RENDERBUFFER:
|
||||
case GL.GL_RENDERBUFFER:
|
||||
System.out.println("Type: Buffer");
|
||||
System.out.println("RB ID: " + rbName);
|
||||
break;
|
||||
@ -1310,17 +1326,17 @@ public class JoglRenderer implements Renderer {
|
||||
private void printRealFrameBufferInfo(FrameBuffer fb) {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
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;
|
||||
gl.glGetIntegerv(GL2.GL_DRAW_BUFFER, intBuf16);
|
||||
gl.glGetIntegerv(GL2GL3.GL_DRAW_BUFFER, intBuf16);
|
||||
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));
|
||||
|
||||
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);
|
||||
gl.glGetIntegerv(GL2.GL_READ_FRAMEBUFFER_BINDING, intBuf16);
|
||||
gl.glGetIntegerv(GL2GL3.GL_READ_FRAMEBUFFER_BINDING, intBuf16);
|
||||
int curReadBinding = intBuf16.get(0);
|
||||
|
||||
System.out.println("=== OpenGL FBO State ===");
|
||||
@ -1333,7 +1349,7 @@ public class JoglRenderer implements Renderer {
|
||||
System.out.println("Read buffer: " + readBuf);
|
||||
|
||||
if (context.boundFBO != fbId) {
|
||||
gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, fbId);
|
||||
gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, fbId);
|
||||
context.boundFBO = fbId;
|
||||
}
|
||||
|
||||
@ -1400,7 +1416,7 @@ public class JoglRenderer implements Renderer {
|
||||
TextureUtil.GLImageFormat glFmt = TextureUtil.getImageFormatWithError(rb.getFormat());
|
||||
|
||||
if (fb.getSamples() > 1 && gl.isExtensionAvailable("GL_EXT_framebuffer_multisample")
|
||||
/*&& gl.isFunctionAvailable("glRenderbufferStorageMultisample")*/) {
|
||||
&& gl.isGL2GL3()/*&& gl.isFunctionAvailable("glRenderbufferStorageMultisample")*/) {
|
||||
int samples = fb.getSamples();
|
||||
if (maxFBOSamples < samples) {
|
||||
samples = maxFBOSamples;
|
||||
@ -1505,11 +1521,13 @@ public class JoglRenderer implements Renderer {
|
||||
Vector2f[] samplePositions = new Vector2f[fb.getSamples()];
|
||||
FloatBuffer samplePos = BufferUtils.createFloatBuffer(2);
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
for (int i = 0; i < samplePositions.length; i++) {
|
||||
gl.getGL2GL3().glGetMultisamplefv(GL2.GL_SAMPLE_POSITION, i, samplePos);
|
||||
samplePos.clear();
|
||||
samplePositions[i] = new Vector2f(samplePos.get(0) - 0.5f,
|
||||
samplePos.get(1) - 0.5f);
|
||||
if (gl.isGL2GL3()) {
|
||||
for (int i = 0; i < samplePositions.length; i++) {
|
||||
gl.getGL2GL3().glGetMultisamplefv(GL2GL3.GL_SAMPLE_POSITION, i, samplePos);
|
||||
samplePos.clear();
|
||||
samplePositions[i] = new Vector2f(samplePos.get(0) - 0.5f,
|
||||
samplePos.get(1) - 0.5f);
|
||||
}
|
||||
}
|
||||
return samplePositions;
|
||||
}
|
||||
@ -1557,11 +1575,15 @@ public class JoglRenderer implements Renderer {
|
||||
}
|
||||
// select back buffer
|
||||
if (context.boundDrawBuf != -1) {
|
||||
gl.getGL2GL3().glDrawBuffer(initialDrawBuf);
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glDrawBuffer(initialDrawBuf);
|
||||
}
|
||||
context.boundDrawBuf = -1;
|
||||
}
|
||||
if (context.boundReadBuf != -1) {
|
||||
gl.getGL2GL3().glReadBuffer(initialReadBuf);
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glReadBuffer(initialReadBuf);
|
||||
}
|
||||
context.boundReadBuf = -1;
|
||||
}
|
||||
|
||||
@ -1591,11 +1613,15 @@ public class JoglRenderer implements Renderer {
|
||||
// make sure to select NONE as draw buf
|
||||
// no color buffer attached. select NONE
|
||||
if (context.boundDrawBuf != -2) {
|
||||
gl.getGL2GL3().glDrawBuffer(GL.GL_NONE);
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glDrawBuffer(GL.GL_NONE);
|
||||
}
|
||||
context.boundDrawBuf = -2;
|
||||
}
|
||||
if (context.boundReadBuf != -2) {
|
||||
gl.getGL2GL3().glReadBuffer(GL.GL_NONE);
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glReadBuffer(GL.GL_NONE);
|
||||
}
|
||||
context.boundReadBuf = -2;
|
||||
}
|
||||
} else {
|
||||
@ -1618,14 +1644,18 @@ public class JoglRenderer implements Renderer {
|
||||
}
|
||||
|
||||
intBuf16.flip();
|
||||
gl.getGL2GL3().glDrawBuffers(intBuf16.limit(), intBuf16);
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glDrawBuffers(intBuf16.limit(), intBuf16);
|
||||
}
|
||||
context.boundDrawBuf = 100 + fb.getNumColorBuffers();
|
||||
}
|
||||
} else {
|
||||
RenderBuffer rb = fb.getColorBuffer(fb.getTargetIndex());
|
||||
// select this draw buffer
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -1656,7 +1686,9 @@ public class JoglRenderer implements Renderer {
|
||||
|
||||
setFrameBuffer(fb);
|
||||
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();
|
||||
}
|
||||
} else {
|
||||
@ -1702,18 +1734,18 @@ public class JoglRenderer implements Renderer {
|
||||
switch (type) {
|
||||
case TwoDimensional:
|
||||
if (samples > 1) {
|
||||
return GL2.GL_TEXTURE_2D_MULTISAMPLE;
|
||||
return GL2GL3.GL_TEXTURE_2D_MULTISAMPLE;
|
||||
} else {
|
||||
return GL.GL_TEXTURE_2D;
|
||||
}
|
||||
case TwoDimensionalArray:
|
||||
if (samples > 1) {
|
||||
return GL2.GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
|
||||
return GL2GL3.GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
|
||||
} else {
|
||||
return GL2.GL_TEXTURE_2D_ARRAY;
|
||||
return GL.GL_TEXTURE_2D_ARRAY;
|
||||
}
|
||||
case ThreeDimensional:
|
||||
return GL2.GL_TEXTURE_3D;
|
||||
return GL2ES2.GL_TEXTURE_3D;
|
||||
case CubeMap:
|
||||
if (face < 0) {
|
||||
return GL.GL_TEXTURE_CUBE_MAP;
|
||||
@ -1801,13 +1833,13 @@ public class JoglRenderer implements Renderer {
|
||||
switch (tex.getType()) {
|
||||
case ThreeDimensional:
|
||||
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 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..
|
||||
// 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;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
|
||||
@ -1816,16 +1848,16 @@ public class JoglRenderer implements Renderer {
|
||||
if (tex.isNeedCompareModeUpdate()) {
|
||||
// R to Texture compare mode
|
||||
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);
|
||||
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 {
|
||||
gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
|
||||
gl.glTexParameteri(target, GL2ES2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
|
||||
}
|
||||
} else {
|
||||
//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();
|
||||
}
|
||||
@ -1869,14 +1901,18 @@ public class JoglRenderer implements Renderer {
|
||||
// No pregenerated mips available,
|
||||
// generate from base level if required
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
// Image already has mipmaps or no mipmap generation desired.
|
||||
// glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0 );
|
||||
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:
|
||||
return GL.GL_UNSIGNED_SHORT;
|
||||
case Int:
|
||||
return GL2.GL_INT;
|
||||
return GL2ES2.GL_INT;
|
||||
case UnsignedInt:
|
||||
return GL.GL_UNSIGNED_INT;
|
||||
// case Half:
|
||||
@ -2064,7 +2100,7 @@ public class JoglRenderer implements Renderer {
|
||||
case Float:
|
||||
return GL.GL_FLOAT;
|
||||
case Double:
|
||||
return GL2.GL_DOUBLE;
|
||||
return GL2GL3.GL_DOUBLE;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown buffer format.");
|
||||
|
||||
@ -2142,7 +2178,7 @@ public class JoglRenderer implements Renderer {
|
||||
for (int i = 0; i < attribList.oldLen; i++) {
|
||||
int idx = attribList.oldList[i];
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
gl.getGL2GL3().glDisableVertexAttribArray(idx);
|
||||
gl.getGL2ES2().glDisableVertexAttribArray(idx);
|
||||
context.boundAttribs[idx] = null;
|
||||
}
|
||||
context.attribIndexList.copyNewToOld();
|
||||
@ -2165,7 +2201,7 @@ public class JoglRenderer implements Renderer {
|
||||
stringBuf.setLength(0);
|
||||
// JOGL 2.0 doesn't need a null terminated string
|
||||
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
|
||||
// the internal name of the enum (Position).
|
||||
@ -2183,7 +2219,7 @@ public class JoglRenderer implements Renderer {
|
||||
|
||||
VertexBuffer[] attribs = context.boundAttribs;
|
||||
if (!context.attribIndexList.moveToNew(loc)) {
|
||||
gl.getGL2GL3().glEnableVertexAttribArray(loc);
|
||||
gl.getGL2ES2().glEnableVertexAttribArray(loc);
|
||||
//System.out.println("Enabled ATTRIB IDX: "+loc);
|
||||
}
|
||||
if (attribs[loc] != vb) {
|
||||
@ -2198,7 +2234,7 @@ public class JoglRenderer implements Renderer {
|
||||
//statistics.onVertexBufferUse(vb, false);
|
||||
}
|
||||
|
||||
gl.getGL2GL3().glVertexAttribPointer(loc,
|
||||
gl.getGL2ES2().glVertexAttribPointer(loc,
|
||||
vb.getNumComponents(),
|
||||
convertFormat(vb.getFormat()),
|
||||
vb.isNormalized(),
|
||||
@ -2219,8 +2255,10 @@ public class JoglRenderer implements Renderer {
|
||||
public void drawTriangleArray(Mesh.Mode mode, int count, int vertCount) {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
if (count > 1) {
|
||||
gl.getGL2GL3().glDrawArraysInstanced(convertElementMode(mode), 0,
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glDrawArraysInstanced(convertElementMode(mode), 0,
|
||||
vertCount, count);
|
||||
}
|
||||
} else {
|
||||
gl.glDrawArrays(convertElementMode(mode), 0, vertCount);
|
||||
}
|
||||
@ -2239,74 +2277,78 @@ public class JoglRenderer implements Renderer {
|
||||
assert bufId != -1;
|
||||
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
if (context.boundElementArrayVBO != bufId) {
|
||||
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, bufId);
|
||||
context.boundElementArrayVBO = bufId;
|
||||
//statistics.onVertexBufferUse(indexBuf, true);
|
||||
} else {
|
||||
//statistics.onVertexBufferUse(indexBuf, true);
|
||||
}
|
||||
if (gl.isGL2GL3()) {
|
||||
if (context.boundElementArrayVBO != bufId) {
|
||||
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, bufId);
|
||||
context.boundElementArrayVBO = bufId;
|
||||
//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();
|
||||
int[] elementLengths = mesh.getElementLengths();
|
||||
if (mesh.getMode() == Mode.Hybrid) {
|
||||
int[] modeStart = mesh.getModeStart();
|
||||
int[] elementLengths = mesh.getElementLengths();
|
||||
|
||||
int elMode = convertElementMode(Mode.Triangles);
|
||||
int fmt = convertFormat(indexBuf.getFormat());
|
||||
int elSize = indexBuf.getFormat().getComponentSize();
|
||||
int listStart = modeStart[0];
|
||||
int stripStart = modeStart[1];
|
||||
int fanStart = modeStart[2];
|
||||
int curOffset = 0;
|
||||
for (int i = 0; i < elementLengths.length; i++) {
|
||||
if (i == stripStart) {
|
||||
elMode = convertElementMode(Mode.TriangleStrip);
|
||||
} else if (i == fanStart) {
|
||||
elMode = convertElementMode(Mode.TriangleStrip);
|
||||
int elMode = convertElementMode(Mode.Triangles);
|
||||
int fmt = convertFormat(indexBuf.getFormat());
|
||||
int elSize = indexBuf.getFormat().getComponentSize();
|
||||
int listStart = modeStart[0];
|
||||
int stripStart = modeStart[1];
|
||||
int fanStart = modeStart[2];
|
||||
int curOffset = 0;
|
||||
for (int i = 0; i < elementLengths.length; i++) {
|
||||
if (i == stripStart) {
|
||||
elMode = convertElementMode(Mode.TriangleStrip);
|
||||
} else if (i == fanStart) {
|
||||
elMode = convertElementMode(Mode.TriangleStrip);
|
||||
}
|
||||
int elementLength = elementLengths[i];
|
||||
|
||||
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*/;
|
||||
}
|
||||
int elementLength = elementLengths[i];
|
||||
|
||||
} else {
|
||||
if (useInstancing) {
|
||||
|
||||
indexBuf.getData().position(curOffset);
|
||||
indexBuf.getData().limit(curOffset + elementLength);
|
||||
|
||||
gl.getGL2GL3().glDrawElementsInstanced(elMode,
|
||||
elementLength,
|
||||
fmt,
|
||||
gl.getGL2GL3().glDrawElementsInstanced(convertElementMode(mesh.getMode()),
|
||||
indexBuf.getData().limit(),
|
||||
convertFormat(indexBuf.getFormat()),
|
||||
indexBuf.getData(),
|
||||
count);
|
||||
|
||||
} else {
|
||||
gl.getGL2GL3().glDrawRangeElements(elMode,
|
||||
gl.getGL2GL3().glDrawRangeElements(convertElementMode(mesh.getMode()),
|
||||
0,
|
||||
vertCount,
|
||||
elementLength,
|
||||
fmt,
|
||||
curOffset);
|
||||
indexBuf.getData().limit(),
|
||||
convertFormat(indexBuf.getFormat()),
|
||||
0);
|
||||
}
|
||||
|
||||
//FIXME check whether elSize is required
|
||||
curOffset += elementLength/* * elSize*/;
|
||||
}
|
||||
} else {
|
||||
if (useInstancing) {
|
||||
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);
|
||||
}
|
||||
//FIXME: ES impl
|
||||
}
|
||||
}
|
||||
|
||||
@ -2339,13 +2381,17 @@ public class JoglRenderer implements Renderer {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
if (id == -1) {
|
||||
IntBuffer temp = intBuf1;
|
||||
gl.getGL2GL3().glGenVertexArrays(1, temp);
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glGenVertexArrays(1, temp);
|
||||
}
|
||||
id = temp.get(0);
|
||||
mesh.setId(id);
|
||||
}
|
||||
|
||||
if (context.boundVertexArray != id) {
|
||||
gl.getGL2GL3().glBindVertexArray(id);
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glBindVertexArray(id);
|
||||
}
|
||||
context.boundVertexArray = id;
|
||||
}
|
||||
|
||||
@ -2380,7 +2426,9 @@ public class JoglRenderer implements Renderer {
|
||||
|
||||
if (context.boundVertexArray != mesh.getId()) {
|
||||
GL gl = GLContext.getCurrentGL();
|
||||
gl.getGL2GL3().glBindVertexArray(mesh.getId());
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glBindVertexArray(mesh.getId());
|
||||
}
|
||||
context.boundVertexArray = mesh.getId();
|
||||
}
|
||||
|
||||
@ -2457,14 +2505,20 @@ public class JoglRenderer implements Renderer {
|
||||
gl.glActiveTexture(GL.GL_TEXTURE0);
|
||||
context.boundTextureUnit = 0;
|
||||
}
|
||||
gl.glDisable(GL2.GL_POINT_SPRITE);
|
||||
gl.glDisable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
if (gl.isGL2ES1()) {
|
||||
gl.glDisable(GL2ES1.GL_POINT_SPRITE);
|
||||
}
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.glDisable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
}
|
||||
context.pointSprite = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (context.pointSize != mesh.getPointSize()) {
|
||||
gl.getGL2GL3().glPointSize(mesh.getPointSize());
|
||||
if (gl.isGL2GL3()) {
|
||||
gl.getGL2GL3().glPointSize(mesh.getPointSize());
|
||||
}
|
||||
context.pointSize = mesh.getPointSize();
|
||||
}
|
||||
if (context.lineWidth != mesh.getLineWidth()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user