Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContextAttribs and PixelFormat builder without unexpected behaviour #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
259 changes: 135 additions & 124 deletions src/java/org/lwjgl/opengl/ContextAttribs.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,45 +65,46 @@ public final class ContextAttribs {

private static final int CONTEXT_ROBUST_ACCESS_BIT_ARB = 0x00000004;
private static final int CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB = 0x8256;
private static final int
NO_RESET_NOTIFICATION_ARB = 0x8261,
LOSE_CONTEXT_ON_RESET_ARB = 0x8252;
private static final int NO_RESET_NOTIFICATION_ARB = 0x8261;
private static final int LOSE_CONTEXT_ON_RESET_ARB = 0x8252;

private static final int CONTEXT_RESET_ISOLATION_BIT_ARB = 0x00000008;

private int majorVersion;
private int minorVersion;
private final int majorVersion;
private final int minorVersion;

private int layerPlane;
private final int layerPlane;

private boolean debug;
private boolean forwardCompatible;
private boolean robustAccess;
private final boolean debug;
private final boolean forwardCompatible;
private final boolean robustAccess;

private boolean profileCore;
private boolean profileCompatibility;
private boolean profileES;
private final boolean profileCore;
private final boolean profileCompatibility;
private final boolean profileES;

private boolean loseContextOnReset;
private boolean contextResetIsolation;
private final boolean loseContextOnReset;
private final boolean contextResetIsolation;

public ContextAttribs() {
this(1, 0);
}

private ContextAttribs(Builder builder) {
this.majorVersion = builder.majorVersion;
this.minorVersion = builder.minorVersion;

public ContextAttribs(final int majorVersion, final int minorVersion) {
if ( majorVersion < 0 || 4 < majorVersion ||
minorVersion < 0 ||
(majorVersion == 4 && 3 < minorVersion) ||
(majorVersion == 3 && 3 < minorVersion) ||
(majorVersion == 2 && 1 < minorVersion) ||
(majorVersion == 1 && 5 < minorVersion) )
throw new IllegalArgumentException("Invalid OpenGL version specified: " + majorVersion + '.' + minorVersion);

this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
}
this.layerPlane = builder.layerPlane;

this.debug = builder.debug;
this.forwardCompatible = builder.forwardCompatible;
this.robustAccess = builder.robustAccess;

this.profileCore = builder.profileCore;
this.profileCompatibility = builder.profileCompatibility;
this.profileES = builder.profileES;

this.loseContextOnReset = builder.loseContextOnReset;
this.contextResetIsolation = builder.contextResetIsolation;
}

private ContextAttribs(final ContextAttribs attribs) {
this.majorVersion = attribs.majorVersion;
this.minorVersion = attribs.minorVersion;
Expand All @@ -119,138 +120,148 @@ private ContextAttribs(final ContextAttribs attribs) {
this.profileES = attribs.profileES;

this.loseContextOnReset = attribs.loseContextOnReset;
this.contextResetIsolation = attribs.contextResetIsolation;
}

public static class Builder {
private int majorVersion;
private int minorVersion;

public int getMajorVersion() {
return majorVersion;
}
private int layerPlane;

public int getMinorVersion() {
return minorVersion;
}
private boolean debug;
private boolean forwardCompatible;
private boolean robustAccess;

public int getLayerPlane() {
return layerPlane;
}

public boolean isDebug() {
return debug;
}

public boolean isForwardCompatible() {
return forwardCompatible;
}
private boolean profileCore;
private boolean profileCompatibility;
private boolean profileES;

public boolean isProfileCore() {
return profileCore;
}
private boolean loseContextOnReset;
private boolean contextResetIsolation;

public boolean isProfileCompatibility() {
return profileCompatibility;
}

public Builder() {
this(1, 0);
}

public boolean isProfileES() {
return profileES;
}
public Builder(final int majorVersion, final int minorVersion) {
if ( majorVersion < 0 || 4 < majorVersion ||
minorVersion < 0 ||
(majorVersion == 4 && 3 < minorVersion) ||
(majorVersion == 3 && 3 < minorVersion) ||
(majorVersion == 2 && 1 < minorVersion) ||
(majorVersion == 1 && 5 < minorVersion) )
throw new IllegalArgumentException("Invalid OpenGL version specified: " + majorVersion + '.' + minorVersion);

this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
}

public ContextAttribs withLayer(final int layerPlane) {
if ( layerPlane < 0 )
throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
public Builder withLayer(final int layerPlane) {
if ( layerPlane < 0 )
throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);

if ( layerPlane == this.layerPlane )
this.layerPlane = layerPlane;
return this;
}

final ContextAttribs attribs = new ContextAttribs(this);
attribs.layerPlane = layerPlane;
return attribs;
}
public Builder withDebug(final boolean debug) {
this.debug = debug;
return this;
}

public ContextAttribs withDebug(final boolean debug) {
if ( debug == this.debug )
public Builder withForwardCompatible(final boolean forwardCompatible) {
this.forwardCompatible = forwardCompatible;
return this;
}

final ContextAttribs attribs = new ContextAttribs(this);
attribs.debug = debug;
return attribs;
}
public Builder withProfileCore(final boolean profileCore) {
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");

this.profileCore = profileCore;
if ( profileCore )
this.profileCompatibility = false;

public ContextAttribs withForwardCompatible(final boolean forwardCompatible) {
if ( forwardCompatible == this.forwardCompatible )
return this;
}

final ContextAttribs attribs = new ContextAttribs(this);
attribs.forwardCompatible = forwardCompatible;
return attribs;
}
public Builder withProfileCompatibility(final boolean profileCompatibility) {
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");

public ContextAttribs withProfileCore(final boolean profileCore) {
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");
this.profileCompatibility = profileCompatibility;
if ( profileCompatibility )
this.profileCore = false;

if ( profileCore == this.profileCore )
return this;
}

final ContextAttribs attribs = new ContextAttribs(this);
attribs.profileCore = profileCore;
if ( profileCore )
attribs.profileCompatibility = false;
public Builder withProfileES(final boolean profileES) {
if ( !(majorVersion == 2 && minorVersion == 0) )
throw new IllegalArgumentException("The OpenGL ES profiles is only supported for OpenGL version 2.0.");

return attribs;
}

public ContextAttribs withProfileCompatibility(final boolean profileCompatibility) {
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");
this.profileES = profileES;

if ( profileCompatibility == this.profileCompatibility )
return this;
}

final ContextAttribs attribs = new ContextAttribs(this);
attribs.profileCompatibility = profileCompatibility;
if ( profileCompatibility )
attribs.profileCore = false;
/**
* Returns a ContextAttribs instance with CONTEXT_RESET_NOTIFICATION_STRATEGY set
* to LOSE_CONTEXT_ON_RESET if the parameter is true or to NO_RESET_NOTIFICATION
* if the parameter is false.
*
* @param loseContextOnReset
*
* @return the new ContextAttribs
*/
public Builder withLoseContextOnReset(final boolean loseContextOnReset) {
this.loseContextOnReset = loseContextOnReset;
return this;
}

return attribs;
public Builder withContextResetIsolation(final boolean contextResetIsolation) {
this.contextResetIsolation = contextResetIsolation;
return this;
}

public ContextAttribs build() {
return new ContextAttribs(this);
}
}


public ContextAttribs withProfileES(final boolean profileES) {
if ( !(majorVersion == 2 && minorVersion == 0) )
throw new IllegalArgumentException("The OpenGL ES profiles is only supported for OpenGL version 2.0.");
public int getMajorVersion() {
return majorVersion;
}

if ( profileES == this.profileES )
return this;
public int getMinorVersion() {
return minorVersion;
}

final ContextAttribs attribs = new ContextAttribs(this);
attribs.profileES = profileES;
public int getLayerPlane() {
return layerPlane;
}

return attribs;
public boolean isDebug() {
return debug;
}

/**
* Returns a ContextAttribs instance with CONTEXT_RESET_NOTIFICATION_STRATEGY set
* to LOSE_CONTEXT_ON_RESET if the parameter is true or to NO_RESET_NOTIFICATION
* if the parameter is false.
*
* @param loseContextOnReset
*
* @return the new ContextAttribs
*/
public ContextAttribs withLoseContextOnReset(final boolean loseContextOnReset) {
if ( loseContextOnReset == this.loseContextOnReset )
return this;
public boolean isForwardCompatible() {
return forwardCompatible;
}

final ContextAttribs attribs = new ContextAttribs(this);
attribs.loseContextOnReset = loseContextOnReset;
return attribs;
public boolean isProfileCore() {
return profileCore;
}

public ContextAttribs withContextResetIsolation(final boolean contextResetIsolation) {
if ( contextResetIsolation == this.contextResetIsolation )
return this;
public boolean isProfileCompatibility() {
return profileCompatibility;
}

final ContextAttribs attribs = new ContextAttribs(this);
attribs.contextResetIsolation = contextResetIsolation;
return attribs;
public boolean isProfileES() {
return profileES;
}

private static ContextAttribsImplementation getImplementation() {
Expand Down
Loading