Skip to content

Commit

Permalink
Added debugging outputs in JOGL viewer.
Browse files Browse the repository at this point in the history
When no valid GL3 instance can be obtained, then
extensive logging information about the available
profiles and the active context is printed.
  • Loading branch information
javagl committed Jan 14, 2017
1 parent 6b5c586 commit debd179
Showing 1 changed file with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.awt.Dimension;
import java.util.logging.Logger;

import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL3;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
Expand Down Expand Up @@ -73,13 +74,43 @@ public class GltfViewerJogl extends AbstractGltfViewer
public void init(GLAutoDrawable drawable)
{
initComplete = false;

GL3 gl = (GL3)drawable.getGL();
gl.setSwapInterval(0);

GL glBase = drawable.getGL();
glBase.setSwapInterval(0);

if (!(glBase instanceof GL3))
{
logger.severe("Could not obtain a GL3 instance");
logger.severe(createGlContextDebugString(glBase));
return;
}

initComplete = true;
}


/**
* Create a string with debug information about the given GL instance
*
* @param glBase The GL instance
* @return The string
*/
private String createGlContextDebugString(GL glBase)
{
StringBuilder sb = new StringBuilder();
sb.append("GLProfile: " + getGLProfile()).append("\n");

sb.append("Availability:").append("\n");
for (String profile : GLProfile.GL_PROFILE_LIST_ALL)
{
sb.append(" " + profile + " : " +
GLProfile.isAvailable(profile)).append("\n");
}
sb.append("Context information:\n" +
glBase.getContext().toString()).append("\n");
return sb.toString();
}


@Override
public void display(GLAutoDrawable drawable)
{
Expand Down Expand Up @@ -120,9 +151,9 @@ public void dispose(GLAutoDrawable arg0)
*/
public GltfViewerJogl()
{
GLProfile profile = GLProfile.getMaxProgrammable(true);
GLProfile profile = getGLProfile();
logger.config("GLProfile: " + profile);

GLCapabilities capabilities = new GLCapabilities(profile);
capabilities.setNumSamples(2);
capabilities.setSampleBuffers(true);
Expand All @@ -137,6 +168,16 @@ public GltfViewerJogl()
glContext = new GlContextJogl();
}

/**
* Returns the GLProfile that should be used for creating the GL context
*
* @return The GLProfile
*/
private GLProfile getGLProfile()
{
return GLProfile.getMaxProgrammable(true);
}

@Override
public GlContext getGlContext()
{
Expand All @@ -153,7 +194,10 @@ public Component getRenderComponent()
protected void prepareRender()
{
//gl = new TraceGL3(glComponent.getGL().getGL3(), System.out);
gl = glComponent.getGL().getGL3();

// The check whether this cast is valid was
// done during the initialization:
gl = (GL3)glComponent.getGL();
glContext.setGL(gl);
}

Expand Down

0 comments on commit debd179

Please sign in to comment.