Skip to content

Commit

Permalink
Refactored loading of GLSL capabilities
Browse files Browse the repository at this point in the history
- Fixed bug where versions below 400 that are not in the hardcoded list were just ignored.
- Applied same approach with mapping as with the loadCapabilities for GL.
- Refactored out the commonalities between the two.
-
  • Loading branch information
JoopAue committed Apr 3, 2016
1 parent f8682a3 commit 4592bb0
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,9 @@ private void loadCapabilitiesES() {

private void loadCapabilitiesGL2() {
int oglVer = extractVersion(gl.glGetString(GL.GL_VERSION));
Map<Integer, List<Caps>> versionCapMap = getGLVersionCapabilityMapping();
addCapabilitiesBasedOnVersion(versionCapMap, oglVer);

Map<Integer, List<Caps>> versionCapMap = getVersionCapabilityMapping();

for (Map.Entry<Integer, List<Caps>> entry : versionCapMap.entrySet()) {
if (oglVer >= entry.getKey()) {
for (Caps cap : entry.getValue()) {
caps.add(cap);
}
}
}

// Fix issue in TestRenderToMemory when GL.GL_FRONT is the main
// buffer being used.
Expand All @@ -194,31 +187,22 @@ private void loadCapabilitiesGL2() {
*/
private void loadCapabilitiesGLSL() {
int glslVer = extractVersion(gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION));
Map<Integer, List<Caps>> versionCapMap = getGSLVersionCapabilityMapping();
addCapabilitiesBasedOnVersion(versionCapMap, glslVer);
}

switch (glslVer) {
default:
if (glslVer < 400) {
break;
/**
* Add capabilities for all versions below the given version.
* @param versionCapMap mapping of existing versions and there capabilities
* @param version version to add capabilities for
*/
private void addCapabilitiesBasedOnVersion(Map<Integer, List<Caps>> versionCapMap, int version) {
for (Map.Entry<Integer, List<Caps>> entry : versionCapMap.entrySet()) {
if (version >= entry.getKey()) {
for (Caps cap : entry.getValue()) {
caps.add(cap);
}
// so that future OpenGL revisions wont break jme3
// fall through intentional
case 400:
caps.add(Caps.GLSL400);
case 330:
caps.add(Caps.GLSL330);
case 150:
caps.add(Caps.GLSL150);
case 140:
caps.add(Caps.GLSL140);
case 130:
caps.add(Caps.GLSL130);
case 120:
caps.add(Caps.GLSL120);
case 110:
caps.add(Caps.GLSL110);
case 100:
caps.add(Caps.GLSL100);
break;
}
}
}

Expand Down Expand Up @@ -2714,7 +2698,7 @@ public void setLinearizeSrgbImages(boolean linearize) {
}
}

public Map<Integer,List<Caps>> getVersionCapabilityMapping() {
public Map<Integer,List<Caps>> getGLVersionCapabilityMapping() {

Map<Integer,List<Caps>> map = new TreeMap<>();

Expand All @@ -2728,4 +2712,19 @@ public Map<Integer,List<Caps>> getVersionCapabilityMapping() {

return map;
}

public Map<Integer,List<Caps>> getGSLVersionCapabilityMapping() {
Map<Integer,List<Caps>> map = new TreeMap<>();

map.put(100, Collections.singletonList(Caps.GLSL100));
map.put(110, Collections.singletonList(Caps.GLSL110));
map.put(120, Collections.singletonList(Caps.GLSL120));
map.put(130, Collections.singletonList(Caps.GLSL130));
map.put(140, Collections.singletonList(Caps.GLSL140));
map.put(150, Collections.singletonList(Caps.GLSL150));
map.put(330, Collections.singletonList(Caps.GLSL330));
map.put(400, Collections.singletonList(Caps.GLSL400));

return map;
}
}

0 comments on commit 4592bb0

Please sign in to comment.