Skip to content

Commit

Permalink
feat: Use ShaderCompatibilityHelper for macOS OpenGL 3+ support.
Browse files Browse the repository at this point in the history
This was accidentally removed in #26.
  • Loading branch information
crykn committed Jan 15, 2024
1 parent d3d0e8a commit 08e8d91
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Interpolation;

import de.damios.guacamole.gdx.graphics.ShaderCompatibilityHelper;

/**
* A transition that is using shader code conforming to the <i>GL Transition
* Specification v1</i>. This allows using the shaders provided at
Expand Down Expand Up @@ -101,8 +103,11 @@ public class GLTransitionsShaderTransition extends ShaderTransition {
* "https://github.com/crykn/libgdx-screenmanager/wiki/How-to-use-GL-Transitions#some-example-code">wiki</a>
* for an in-depth explanation and example.
* <p>
* Ignores code in {@link ShaderProgram#prependFragmentCode} and
* {@link ShaderProgram#prependVertexCode}.
* Code in {@link ShaderProgram#prependFragmentCode} and
* {@link ShaderProgram#prependVertexCode} is ignored. The provided shader
* is {@linkplain ShaderCompatibilityHelper#fromString(String, String)
* automatically ported} from from version 120 (~ OpenGL 2.1) to version 150
* (~ OpenGL 3.2) if needed.
*
* @param glTransitionsCode
* the GL Transitions shader code
Expand All @@ -127,8 +132,11 @@ public GLTransitionsShaderTransition(String glTransitionsCode,
* "https://github.com/crykn/libgdx-screenmanager/wiki/How-to-use-GL-Transitions#some-example-code">wiki</a>
* for an in-depth explanation and example.
* <p>
* Ignores code in {@link ShaderProgram#prependFragmentCode} and
* {@link ShaderProgram#prependVertexCode}.
* Code in {@link ShaderProgram#prependFragmentCode} and
* {@link ShaderProgram#prependVertexCode} is ignored. The provided shader
* is {@linkplain ShaderCompatibilityHelper#fromString(String, String)
* automatically ported} from from version 120 (~ OpenGL 2.1) to version 150
* (~ OpenGL 3.2) if needed.
*
* @param glTransitionsCode
* the GL Transitions shader code
Expand All @@ -141,7 +149,7 @@ public GLTransitionsShaderTransition(String glTransitionsCode,
float duration, @Nullable Interpolation interpolation) {
super(VERT_SHADER,
FRAG_SHADER_PREPEND + glTransitionsCode + FRAG_SHADER_POSTPEND,
true, duration, interpolation);
true, duration, interpolation, true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import com.badlogic.gdx.utils.viewport.Viewport;

import de.damios.guacamole.Preconditions;
import de.damios.guacamole.annotations.Beta;
import de.damios.guacamole.gdx.graphics.QuadMeshGenerator;
import de.damios.guacamole.gdx.graphics.ShaderCompatibilityHelper;
import de.damios.guacamole.gdx.graphics.ShaderProgramFactory;
import de.eskalon.commons.screen.transition.TimedTransition;

Expand Down Expand Up @@ -97,13 +99,28 @@ public ShaderTransition(String vert, String frag, boolean ignorePrepend,
* Creates a shader transition. Please note that this entails the shader
* being compiled which needs to happen on the rendering thread!
*
* @param vert
* the vertex shader code
* @param frag
* the fragment shader code
* @param ignorePrepend
* whether to ignore the code in
* {@link ShaderProgram#prependFragmentCode} and
* {@link ShaderProgram#prependVertexCode}
* @param duration
* the transition's duration in seconds
* @param interpolation
* the interpolation to use
*/
public ShaderTransition(String vert, String frag, boolean ignorePrepend,
float duration, @Nullable Interpolation interpolation) {
this(vert, frag, ignorePrepend, duration, interpolation, false);
}

@Beta
public ShaderTransition(String vert, String frag, boolean ignorePrepend,
float duration, @Nullable Interpolation interpolation,
boolean useCompatibilityHandler) {
super(duration, interpolation);

Preconditions.checkNotNull(vert, "The vertex shader cannot be null.");
Expand All @@ -114,8 +131,13 @@ public ShaderTransition(String vert, String frag, boolean ignorePrepend,
// screen

// Compile the shader; this needs to happen on the rendering thread!
this.program = ShaderProgramFactory.fromString(vert, frag, true,
ignorePrepend);
if (useCompatibilityHandler)
this.program = ShaderCompatibilityHelper.fromString(vert, frag); // ignorePrepend
// is
// ignored
else
this.program = ShaderProgramFactory.fromString(vert, frag, true,
ignorePrepend);

this.projTransLoc = this.program.getUniformLocation("u_projTrans");
this.lastScreenLoc = this.program.getUniformLocation("lastScreen");
Expand Down

0 comments on commit 08e8d91

Please sign in to comment.