Skip to content

Commit

Permalink
Merge branch 'gl-render-maintainable' of github.com:JoopAue/jmonkeyen…
Browse files Browse the repository at this point in the history
…gine into gl-render-maintainable
  • Loading branch information
JoopAue committed Apr 5, 2016
2 parents 8280e2b + 4a944e5 commit e73b344
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
public class GLCapabilities {

private static final Logger logger = Logger.getLogger(GLCapabilities.class.getName());
private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
protected final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
private static final Pattern GLVERSION_PATTERN = Pattern.compile(".*?(\\d+)\\.(\\d+).*");
private final EnumMap<Limits, Integer> limits = new EnumMap<>(Limits.class);
protected final EnumMap<Limits, Integer> limits = new EnumMap<>(Limits.class);

private final IntBuffer intBuf16 = BufferUtils.createIntBuffer(16);
private GL gl;
Expand All @@ -45,7 +45,7 @@ public void loadCapabilities(GL gl, GL2 gl2, GL3 gl3, RenderContext context) {
* Load Embedded System Capabilities.
* Important: Do not add OpenGL20 - that's the desktop capability!
*/
private void loadCapabilitiesES() {
protected void loadCapabilitiesES() {
caps.add(Caps.GLSL100);
caps.add(Caps.OpenGLES20);
}
Expand Down Expand Up @@ -399,7 +399,7 @@ private boolean hasExtension(String extensionName) {
return extensions.contains(extensionName);
}

private int getInteger(int en) {
protected int getInteger(int en) {
intBuf16.clear();
gl.glGetInteger(en, intBuf16);
return intBuf16.get(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package com.jme3.renderer.opengl;


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

import java.util.HashSet;

import static org.junit.Assert.*;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;

public class GLCapabilitiesTest {

private GLCapabilities c_gl2;
private GLCapabilities c;
@Mock
private GL gl;
@Mock
private GL2 gl2;
@Mock
private GL3 gl3;
@Mock
private RenderContext context;

@Before
public void setUp() throws Exception {
initMocks(this);
c_gl2 = spy(new GLCapabilities());
c = spy(new GLCapabilities());

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

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

c_gl2.loadCapabilities(gl, gl2, gl3, context);

String str = null;
verify(c_gl2).loadCapabilitiesGL2(eq(str), eq(context));
verify(c_gl2).loadCapabilitiesGLSL(eq(str));
verify(c_gl2).loadCapabilitiesGLSL1Support();
verify(c_gl2).loadCapabilitiesCommon();
}

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

c.loadCapabilities(gl, null, gl3, context);

verify(c).loadCapabilitiesES();
verify(c).loadCapabilitiesCommon();
}

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

c_gl2.loadCapabilities(gl, gl2, gl3, context);

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

assertTrue(context.initialDrawBuf == c_gl2.getInteger(GL2.GL_DRAW_BUFFER));
assertTrue(context.initialReadBuf == c_gl2.getInteger(GL2.GL_READ_BUFFER));
}

@Test
public void loadCapabilitiesGL2NotRealVersion() throws Exception {
doReturn(213).when(c_gl2).extractVersion(null);

c_gl2.loadCapabilities(gl, gl2, gl3, context);

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

@Test
public void loadCapabilitiesGLSL() throws Exception {

}

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

c_gl2.loadCapabilities(gl, gl2, gl3, context);

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

@Test
public void loadCapabilitiesGLSLNotRealVersion() throws Exception {
doReturn(124).when(c_gl2).extractVersion(null);

c_gl2.loadCapabilities(gl, gl2, gl3, context);

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

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

c_gl2.loadCapabilities(gl, gl2, gl3, context);

assertTrue(c_gl2.caps.contains(Caps.GLSL110));
assertTrue(c_gl2.caps.contains(Caps.GLSL100));
}

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

c.loadCapabilities(gl, null, gl3, context);

assertTrue(c.caps.contains(Caps.GLSL100));
assertTrue(c.caps.contains(Caps.OpenGLES20));
}

@Test
public void loadCapabilitiesCommon() {
doReturn(310).when(c_gl2).extractVersion(null);

c_gl2.loadCapabilities(gl, gl2, gl3, context);

verify(c_gl2).loadExtensions();
assertTrue(c_gl2.limits.get(Limits.VertexTextureUnits) == c_gl2.getInteger(GL.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS));
assertFalse(c_gl2.caps.contains(Caps.VertexTextureFetch));
assertTrue(c_gl2.limits.get(Limits.FragmentTextureUnits) == c_gl2.getInteger(GL.GL_MAX_TEXTURE_IMAGE_UNITS));
assertTrue(c_gl2.limits.get(Limits.VertexUniformVectors) == c_gl2.getInteger(GL.GL_MAX_VERTEX_UNIFORM_VECTORS));
assertTrue(c_gl2.limits.get(Limits.VertexAttributes) == c_gl2.getInteger(GL.GL_MAX_VERTEX_ATTRIBS));
assertTrue(c_gl2.limits.get(Limits.TextureSize) == c_gl2.getInteger(GL.GL_MAX_TEXTURE_SIZE));
assertTrue(c_gl2.limits.get(Limits.CubemapSize) == c_gl2.getInteger(GL.GL_MAX_CUBE_MAP_TEXTURE_SIZE));
assertFalse(c_gl2.caps.contains(Caps.MeshInstancing));
assertTrue(c_gl2.caps.contains(Caps.IntegerIndexBuffer));
assertFalse(c_gl2.caps.contains(Caps.TextureBuffer));

// texture format
assertTrue(c_gl2.caps.contains(Caps.OpenGL30));
assertTrue(c_gl2.caps.contains(Caps.FloatTexture));
assertTrue(c_gl2.caps.contains(Caps.DepthTexture));
assertFalse(c_gl2.caps.contains(Caps.Rgba8));
assertTrue(c_gl2.caps.contains(Caps.PackedDepthStencilBuffer));
assertFalse(c_gl2.caps.contains(Caps.FloatColorBuffer));
assertFalse(c_gl2.caps.contains(Caps.FloatDepthBuffer));
assertTrue(c_gl2.caps.contains(Caps.PackedFloatColorBuffer));
assertTrue(c_gl2.caps.contains(Caps.PackedFloatTexture));
assertTrue(c_gl2.caps.contains(Caps.SharedExponentTexture));
assertFalse(c_gl2.caps.contains(Caps.TextureCompressionS3TC));
assertFalse(c_gl2.caps.contains(Caps.TextureCompressionETC2));
assertFalse(c_gl2.caps.contains(Caps.TextureCompressionETC1));
assertFalse(c_gl2.caps.contains(Caps.TextureCompressionETC1));
// end texture format

assertTrue(c_gl2.caps.contains(Caps.VertexBufferArray));
assertTrue(c_gl2.caps.contains(Caps.NonPowerOfTwoTextures));
assertFalse(c_gl2.caps.contains(Caps.PartialNonPowerOfTwoTextures));
assertTrue(c_gl2.caps.contains(Caps.TextureArray));
assertFalse(c_gl2.caps.contains(Caps.TextureFilterAnisotropic));
assertFalse(c_gl2.limits.containsKey(Limits.TextureAnisotropy));

// big if statement
assertTrue(c_gl2.caps.contains(Caps.FrameBuffer));
assertTrue(c_gl2.limits.get(Limits.RenderBufferSize) == c_gl2.getInteger(GLFbo.GL_MAX_RENDERBUFFER_SIZE_EXT));
assertTrue(c_gl2.limits.get(Limits.FrameBufferAttachments) == c_gl2.getInteger(GLFbo.GL_MAX_COLOR_ATTACHMENTS_EXT));
assertTrue(c_gl2.caps.contains(Caps.FrameBufferBlit));
assertFalse(c_gl2.caps.contains(Caps.FrameBufferMultisample));
assertFalse(c_gl2.limits.containsKey(Limits.FrameBufferSamples));
assertFalse(c_gl2.caps.contains(Caps.TextureMultisample));
assertFalse(c_gl2.limits.containsKey(Limits.ColorTextureSamples));
assertFalse(c_gl2.limits.containsKey(Limits.DepthTextureSamples));
assertTrue(c_gl2.limits.get(Limits.FrameBufferMrtAttachments) == c_gl2.getInteger(GLExt.GL_MAX_DRAW_BUFFERS_ARB));
assertFalse(c_gl2.caps.contains(Caps.FrameBufferMRT));
// end big if statement

assertFalse(c_gl2.caps.contains(Caps.Multisample));
assertTrue(c_gl2.caps.contains(Caps.Srgb));
assertFalse(c_gl2.caps.contains(Caps.SeamlessCubemap));
assertFalse(c_gl2.caps.contains(Caps.CoreProfile));
assertFalse(c_gl2.caps.contains(Caps.BinaryShader));
}
}
Loading

0 comments on commit e73b344

Please sign in to comment.