Improves OpenGL-ES support (especially for Raspberry Pi), contribution of Erkki Nokso-Koivisto
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10269 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
7534d90dde
commit
0acece86e0
@ -2277,39 +2277,39 @@ public class JoglRenderer implements Renderer {
|
|||||||
assert bufId != -1;
|
assert bufId != -1;
|
||||||
|
|
||||||
GL gl = GLContext.getCurrentGL();
|
GL gl = GLContext.getCurrentGL();
|
||||||
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();
|
if (context.boundElementArrayVBO != bufId) {
|
||||||
boolean useInstancing = count > 1 && caps.contains(Caps.MeshInstancing);
|
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, bufId);
|
||||||
|
context.boundElementArrayVBO = bufId;
|
||||||
|
//statistics.onVertexBufferUse(indexBuf, true);
|
||||||
|
} else {
|
||||||
|
//statistics.onVertexBufferUse(indexBuf, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (mesh.getMode() == Mode.Hybrid) {
|
int vertCount = mesh.getVertexCount();
|
||||||
int[] modeStart = mesh.getModeStart();
|
boolean useInstancing = count > 1 && caps.contains(Caps.MeshInstancing);
|
||||||
int[] elementLengths = mesh.getElementLengths();
|
|
||||||
|
|
||||||
int elMode = convertElementMode(Mode.Triangles);
|
if (mesh.getMode() == Mode.Hybrid) {
|
||||||
int fmt = convertFormat(indexBuf.getFormat());
|
int[] modeStart = mesh.getModeStart();
|
||||||
int elSize = indexBuf.getFormat().getComponentSize();
|
int[] elementLengths = mesh.getElementLengths();
|
||||||
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) {
|
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) {
|
||||||
|
if (gl.isGL2GL3()) {
|
||||||
indexBuf.getData().position(curOffset);
|
indexBuf.getData().position(curOffset);
|
||||||
indexBuf.getData().limit(curOffset + elementLength);
|
indexBuf.getData().limit(curOffset + elementLength);
|
||||||
|
|
||||||
@ -2318,43 +2318,63 @@ public class JoglRenderer implements Renderer {
|
|||||||
fmt,
|
fmt,
|
||||||
indexBuf.getData(),
|
indexBuf.getData(),
|
||||||
count);
|
count);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"instancing is not supported.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (gl.isGL2GL3()) {
|
||||||
gl.getGL2GL3().glDrawRangeElements(elMode,
|
gl.getGL2GL3().glDrawRangeElements(elMode,
|
||||||
0,
|
0,
|
||||||
vertCount,
|
vertCount,
|
||||||
elementLength,
|
elementLength,
|
||||||
fmt,
|
fmt,
|
||||||
curOffset);
|
curOffset);
|
||||||
|
} else {
|
||||||
|
indexBuf.getData().position(curOffset);
|
||||||
|
gl.glDrawElements(elMode, elementLength, fmt,
|
||||||
|
indexBuf.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME check whether elSize is required
|
|
||||||
curOffset += elementLength/* * elSize*/;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (useInstancing) {
|
//FIXME check whether elSize is required
|
||||||
|
curOffset += elementLength * elSize;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (useInstancing) {
|
||||||
|
if (gl.isGL2GL3()) {
|
||||||
gl.getGL2GL3().glDrawElementsInstanced(convertElementMode(mesh.getMode()),
|
gl.getGL2GL3().glDrawElementsInstanced(convertElementMode(mesh.getMode()),
|
||||||
indexBuf.getData().limit(),
|
indexBuf.getData().limit(),
|
||||||
convertFormat(indexBuf.getFormat()),
|
convertFormat(indexBuf.getFormat()),
|
||||||
indexBuf.getData(),
|
indexBuf.getData(),
|
||||||
count);
|
count);
|
||||||
} else {
|
} else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"instancing is not supported.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (gl.isGL2GL3()) {
|
||||||
gl.getGL2GL3().glDrawRangeElements(convertElementMode(mesh.getMode()),
|
gl.getGL2GL3().glDrawRangeElements(convertElementMode(mesh.getMode()),
|
||||||
0,
|
0,
|
||||||
vertCount,
|
vertCount,
|
||||||
indexBuf.getData().limit(),
|
indexBuf.getData().limit(),
|
||||||
convertFormat(indexBuf.getFormat()),
|
convertFormat(indexBuf.getFormat()),
|
||||||
0);
|
0);
|
||||||
|
} else {
|
||||||
|
indexBuf.getData().rewind();
|
||||||
|
gl.glDrawElements(convertElementMode(mesh.getMode()),
|
||||||
|
indexBuf.getData().limit(),
|
||||||
|
convertFormat(indexBuf.getFormat()), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//FIXME: ES impl
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************\
|
/**
|
||||||
|* Render Calls *|
|
* *******************************************************************\ |*
|
||||||
\*********************************************************************/
|
* Render Calls *|
|
||||||
|
\********************************************************************
|
||||||
|
*/
|
||||||
private int convertElementMode(Mesh.Mode mode) {
|
private int convertElementMode(Mesh.Mode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case Points:
|
case Points:
|
||||||
@ -2379,25 +2399,21 @@ public class JoglRenderer implements Renderer {
|
|||||||
public void updateVertexArray(Mesh mesh) {
|
public void updateVertexArray(Mesh mesh) {
|
||||||
int id = mesh.getId();
|
int id = mesh.getId();
|
||||||
GL gl = GLContext.getCurrentGL();
|
GL gl = GLContext.getCurrentGL();
|
||||||
//FIXME rather use GLCaps and do it once for all
|
|
||||||
boolean isVaoSupported = gl.isFunctionAvailable("glGenVertexArrays") &&
|
|
||||||
gl.isFunctionAvailable("glBindVertexArray");
|
|
||||||
if (isVaoSupported) {
|
|
||||||
if (id == -1) {
|
|
||||||
IntBuffer temp = intBuf1;
|
|
||||||
if (gl.isGL2GL3()) {
|
|
||||||
gl.getGL2GL3().glGenVertexArrays(1, temp);
|
|
||||||
}
|
|
||||||
id = temp.get(0);
|
|
||||||
mesh.setId(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.boundVertexArray != id) {
|
if (id == -1) {
|
||||||
if (gl.isGL2GL3()) {
|
IntBuffer temp = intBuf1;
|
||||||
gl.getGL2GL3().glBindVertexArray(id);
|
if (gl.isGL2GL3()) {
|
||||||
}
|
gl.getGL2GL3().glGenVertexArrays(1, temp);
|
||||||
context.boundVertexArray = id;
|
|
||||||
}
|
}
|
||||||
|
id = temp.get(0);
|
||||||
|
mesh.setId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.boundVertexArray != id) {
|
||||||
|
if (gl.isGL2GL3()) {
|
||||||
|
gl.getGL2GL3().glBindVertexArray(id);
|
||||||
|
}
|
||||||
|
context.boundVertexArray = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
|
VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user