Skip to content

Commit

Permalink
Tests for loadCapabilitiesGL2
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinfjola committed Apr 3, 2016
1 parent bab8705 commit 1eaab97
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 7 deletions.
14 changes: 7 additions & 7 deletions jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import java.util.regex.Pattern;
import jme3tools.shader.ShaderDebug;

public final class GLRenderer implements Renderer {
public class GLRenderer implements Renderer {

private static final Logger logger = Logger.getLogger(GLRenderer.class.getName());
private static final boolean VALIDATE_SHADER = false;
Expand All @@ -81,9 +81,9 @@ public final class GLRenderer implements Renderer {
private final IntBuffer intBuf1 = BufferUtils.createIntBuffer(1);
private final IntBuffer intBuf16 = BufferUtils.createIntBuffer(16);
private final FloatBuffer floatBuf16 = BufferUtils.createFloatBuffer(16);
private final RenderContext context = new RenderContext();
protected final RenderContext context = new RenderContext();
private final NativeObjectManager objManager = new NativeObjectManager();
private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
protected final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
private final EnumMap<Limits, Integer> limits = new EnumMap<Limits, Integer>(Limits.class);

private FrameBuffer mainFbOverride = null;
Expand Down Expand Up @@ -126,7 +126,7 @@ public EnumMap<Limits, Integer> getLimits() {
return limits;
}

private HashSet<String> loadExtensions() {
protected HashSet<String> loadExtensions() {
HashSet<String> extensionSet = new HashSet<String>(64);
if (caps.contains(Caps.OpenGL30)) {
// If OpenGL3+ is available, use the non-deprecated way
Expand All @@ -143,7 +143,7 @@ private HashSet<String> loadExtensions() {
return extensionSet;
}

public static int extractVersion(String version) {
public int extractVersion(String version) {
Matcher m = GLVERSION_PATTERN.matcher(version);
if (m.matches()) {
int major = Integer.parseInt(m.group(1));
Expand All @@ -170,7 +170,7 @@ private void loadCapabilitiesES() {
// Important: Do not add OpenGL20 - that's the desktop capability!
}

private void loadCapabilitiesGL2() {
protected void loadCapabilitiesGL2() {
int oglVer = extractVersion(gl.glGetString(GL.GL_VERSION));

if (oglVer >= 200) {
Expand Down Expand Up @@ -480,7 +480,7 @@ private void loadCapabilitiesCommon() {
texUtil.initialize(caps);
}

private void loadCapabilities() {
protected void loadCapabilities() {
if (gl2 != null) {
loadCapabilitiesGL2();
} else {
Expand Down
106 changes: 106 additions & 0 deletions jme3-core/src/test/java/com/jme3/renderer/opengl/GLRendererTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.jme3.renderer.opengl;

import com.jme3.renderer.Caps;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;

import java.util.HashSet;

import static org.junit.Assert.*;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.Mockito.*;

public class GLRendererTest {

private GLRenderer r;
@Mock
private GL2 gl;
@Mock
private GLExt glExt;
@Mock
private GLFbo glFbo;

@Before
public void setUp() throws Exception {
initMocks(this);
r = spy(new GLRenderer(gl, glExt, glFbo));


doReturn(new HashSet<String>()).when(r).loadExtensions();
}

@Test
public void initialize() {
doReturn(310).when(r).extractVersion(null);

r.initialize();

verify(r).loadCapabilities();
verify(r).loadCapabilitiesGL2();
}


@Test
public void loadCapabilitiesGL2Common() throws Exception {
doReturn(310).when(r).extractVersion(null);

r.initialize();

assertTrue(r.caps.contains(Caps.GLSL110));
assertTrue(r.caps.contains(Caps.GLSL100));

assertNotNull(r.context.initialDrawBuf);
assertNotNull(r.context.initialReadBuf);
}

@Test
public void loadCapabilitiesGL2oglVer() throws Exception {
doReturn(310).when(r).extractVersion(null);

r.initialize();

assertTrue(r.caps.contains(Caps.OpenGL20));
assertTrue(r.caps.contains(Caps.OpenGL21));
assertTrue(r.caps.contains(Caps.OpenGL30));
assertTrue(r.caps.contains(Caps.OpenGL31));
assertFalse(r.caps.contains(Caps.OpenGL32));
assertFalse(r.caps.contains(Caps.OpenGL33));
assertFalse(r.caps.contains(Caps.OpenGL40));
}

@Test
public void loadCapabilitiesGL2glslVer() throws Exception {
doReturn(150).when(r).extractVersion(null);

r.initialize();

assertTrue(r.caps.contains(Caps.GLSL150));
assertTrue(r.caps.contains(Caps.GLSL140));
assertTrue(r.caps.contains(Caps.GLSL130));
assertTrue(r.caps.contains(Caps.GLSL120));
assertTrue(r.caps.contains(Caps.GLSL110));
assertTrue(r.caps.contains(Caps.GLSL100));
assertFalse(r.caps.contains(Caps.GLSL400));
assertFalse(r.caps.contains(Caps.GLSL330));
}

public class TestGLRenderer extends GLRenderer {

public TestGLRenderer(GL gl, GLExt glext, GLFbo glfbo) {
super(gl, glext, glfbo);
}
/*
@Override
public int extractVersion(String version) {
return 200;
}
*/

@Override
protected HashSet<String> loadExtensions() {
return new HashSet<String>();
}
}
}

0 comments on commit 1eaab97

Please sign in to comment.