Skip to content

Commit

Permalink
Improve compatibility with GLES back-end
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed Mar 10, 2024
1 parent b9b1b95 commit e3f5e07
Show file tree
Hide file tree
Showing 62 changed files with 182 additions and 195 deletions.
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/CollectScreenShots.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() {
this.jvmArgs(
"-DtakeScreenshot=true",
"-DscreenshotPath=${outputDir.get().asFile}/$imageName.png",
"-Dorg.openrndr.exceptions=JVM"
"-Dorg.openrndr.exceptions=JVM",
"-Dorg.openrndr.gl3.debug=true",
"-Dorg.openrndr.gl3.delete_angle_on_exit=false"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ dependencies {
"demoImplementation"(main.output.classesDirs + main.runtimeClasspath)
"demoImplementation"(libs.openrndr.application)
"demoImplementation"(libs.openrndr.extensions)

if (DefaultNativePlatform.getCurrentOperatingSystem().isMacOsX) {
"demoRuntimeOnly"(libs.openrndr.gl3.natives.macos.arm64)
}
"demoRuntimeOnly"(libs.openrndr.gl3.core)
"demoRuntimeOnly"(libs.slf4j.simple)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.openrndr.extra.convention

import CollectScreenshotsTask
import gradle.kotlin.dsl.accessors._a37e1a3c5785f18372ed85a4dc9bbdf6.testRuntimeOnly
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI

val libs = the<LibrariesForLibs>()

Expand Down Expand Up @@ -49,6 +48,11 @@ kotlin {
outputDir.set(project.file(project.projectDir.toString() + "/images"))
dependsOn(compileTaskProvider)
}
dependencies {
if (DefaultNativePlatform.getCurrentOperatingSystem().isMacOsX) {
runtimeOnly(libs.openrndr.gl3.natives.macos.arm64)
}
}
}
}
testRuns["test"].executionTask {
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
4 changes: 2 additions & 2 deletions openrndr-demos/src/demo/kotlin/DemoCircleBatch02.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fun main() = application {
// sets angle and radius based on time and shape ID.
drawer.shadeStyle = shadeStyle {
vertexTransform = """
float a = c_instance + p_time * 0.1;
float r = 200 + 100 * sin(a * 0.998);
float a = float(c_instance) + p_time * 0.1;
float r = 200.0 + 100.0 * sin(a * 0.998);
x_position.x += r * sin(a);
x_position.y += r * cos(a);
""".trimIndent()
Expand Down
7 changes: 2 additions & 5 deletions openrndr-demos/src/demo/kotlin/DemoCubemap01.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import org.openrndr.application
import org.openrndr.draw.Cubemap
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.Session
import org.openrndr.draw.shadeStyle
import org.openrndr.draw.*
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.boxMesh

fun main() = application {
program {

val cubemap = Cubemap.fromUrl("file:demo-data/cubemaps/garage_iem.dds", null, session = Session.active)
val cubemap = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active)
val cube = boxMesh()
extend(Orbital()) {

Expand Down
2 changes: 1 addition & 1 deletion openrndr-demos/src/demo/kotlin/DemoCubemap02.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.openrndr.extra.meshgenerators.boxMesh

fun main() = application {
program {
val cubemap1 = Cubemap.fromUrl("file:demo-data/cubemaps/garage_iem.dds", null, session = Session.active)
val cubemap1 = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active)
val cube = boxMesh()
val cubemap2 = cubemap(cubemap1.width, format = cubemap1.format, type = cubemap1.type, levels = 2, session = Session.active)
cubemap1.copyTo(cubemap2, 0, 0)
Expand Down
2 changes: 1 addition & 1 deletion openrndr-demos/src/demo/kotlin/DemoCubemap03.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.openrndr.extra.meshgenerators.boxMesh

fun main() = application {
program {
val cubemap1 = Cubemap.fromUrl("file:demo-data/cubemaps/garage_iem.dds", null, session = Session.active)
val cubemap1 = loadCubemap("demo-data/cubemaps/garage_iem.dds", null, session = Session.active)
val cube = boxMesh()
val cubemap2 = cubemap(cubemap1.width, format = cubemap1.format, type = cubemap1.type, levels = 2, session = Session.active)
cubemap1.copyTo(cubemap2, 0, 0)
Expand Down
6 changes: 3 additions & 3 deletions orx-color/src/commonMain/kotlin/phrases/Phrases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ object ColorPhraseBook : ShaderPhraseBook("color") {
|vec4 linear_rgb_to_srgb(vec4 c) {
| const float t = 0.00313066844250063;
| return vec4(
| c.r <= t ? c.r * 12.92 : 1.055 * pow(c.r, 1 / 2.4) - 0.055,
| c.g <= t ? c.g * 12.92 : 1.055 * pow(c.g, 1 / 2.4) - 0.055,
| c.b <= t ? c.b * 12.92 : 1.055 * pow(c.b, 1 / 2.4) - 0.055,
| c.r <= t ? c.r * 12.92 : 1.055 * pow(c.r, 1.0 / 2.4) - 0.055,
| c.g <= t ? c.g * 12.92 : 1.055 * pow(c.g, 1.0 / 2.4) - 0.055,
| c.b <= t ? c.b * 12.92 : 1.055 * pow(c.b, 1.0 / 2.4) - 0.055,
| c.a);
|}""".trimMargin())

Expand Down
3 changes: 2 additions & 1 deletion orx-compositor/src/jvmDemo/kotlin/DemoCompositor02.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import org.openrndr.shape.Rectangle
* Try changing which layer has multisampling applied and observe the results.
*/
fun main() = application {
System.setProperty("org.openrndr.gl3.debug", "true")
configure {
width = 800
height = 800
}

program {
val layers = compose {
layer(multisample = BufferMultisample.SampleCount(16)) {
layer(multisample = BufferMultisample.SampleCount(4)) {
draw {
drawer.translate(drawer.bounds.center)
drawer.rotate(seconds)
Expand Down
8 changes: 4 additions & 4 deletions orx-fx/src/commonMain/kotlin/blend/BlendSpectral.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ vec3 srgb_to_linear(vec3 c) {
vec3 linear_to_srgb(vec3 c) {
const float t = 0.00313066844250063;
return vec3(
c.r <= t ? c.r * 12.92 : 1.055 * pow(c.r, 1 / 2.4) - 0.055,
c.g <= t ? c.g * 12.92 : 1.055 * pow(c.g, 1 / 2.4) - 0.055,
c.b <= t ? c.b * 12.92 : 1.055 * pow(c.b, 1 / 2.4) - 0.055
c.r <= t ? c.r * 12.92 : 1.055 * pow(c.r, 1.0 / 2.4) - 0.055,
c.g <= t ? c.g * 12.92 : 1.055 * pow(c.g, 1.0 / 2.4) - 0.055,
c.b <= t ? c.b * 12.92 : 1.055 * pow(c.b, 1.0 / 2.4) - 0.055
);
}
Expand Down Expand Up @@ -86,7 +86,7 @@ void main() {
*/
@Suppress("RUNTIME_ANNOTATION_NOT_SUPPORTED")
@Description("Blend spectral")
class BlendSpectral : Filter2to1(filterShaderFromCode(spectralBlendShader, "color-burn")) {
class BlendSpectral : Filter2to1(filterShaderFromCode(spectralBlendShader, "blend-spectral")) {
@BooleanParameter("source clip")
var clip: Boolean by parameters

Expand Down
2 changes: 1 addition & 1 deletion orx-fx/src/commonMain/kotlin/distort/Lenses.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.openrndr.extra.parameters.IntParameter
import org.openrndr.shape.Rectangle

@Description("Lenses")
class Lenses : Filter1to1(mppFilterShader(fx_lenses, "block-repeat")) {
class Lenses : Filter1to1(mppFilterShader(fx_lenses, "lenses")) {
@IntParameter("rows", 1, 64, order = 0)
var rows: Int by parameters

Expand Down
1 change: 0 additions & 1 deletion orx-fx/src/jvmDemo/kotlin/DemoBlur01.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.fx.blur.*
import org.openrndr.math.Polar
import kotlin.math.sin
Expand Down
1 change: 0 additions & 1 deletion orx-fx/src/jvmDemo/kotlin/DemoDitherLumaHalftone01.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import org.openrndr.application
import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.dither.LumaHalftone
import org.openrndr.math.mod_

fun main() {
application {
Expand Down
5 changes: 0 additions & 5 deletions orx-fx/src/jvmDemo/kotlin/DemoFluidDistort01.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ fun main() {
checkers.size = 64.0
checkers.apply(emptyArray(), image)

if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
extend {
fd.blend = mouse.position.x/width
fd.apply(image, distorted)
Expand Down
6 changes: 3 additions & 3 deletions orx-fx/src/shaders/glsl/blend/add.frag
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ void main() {
vec4 b = texture2D(tex1, v_texCoord0);
#endif

vec3 na = a.a > 0 ? a.rgb/a.a : vec3(0.0);
vec3 nb = b.a > 0 ? b.rgb/b.a : vec3(0.0);
vec3 na = a.a > 0.0 ? a.rgb/a.a : vec3(0.0);
vec3 nb = b.a > 0.0 ? b.rgb/b.a : vec3(0.0);

vec3 addColor = b.rgb;

vec4 result;
if (clip) {
result = vec4((na + addColor), 1) * a.a;
result = vec4((na + addColor), 1.0) * a.a;
} else {
result = (1.0-a.a) * b + a.a * b.a * vec4(min(na + nb, vec3(1.0)), 1.0) + (1.0-b.a) * a;
}
Expand Down
6 changes: 3 additions & 3 deletions orx-fx/src/shaders/glsl/blend/hard-light.frag
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ void main() {
vec3 nb = b.a == 0.0 ? vec3(0.0): b.rgb / b.a;

vec3 m = vec3(
nb.r <= 0.5? 2*na.r * nb.r : 1.0 - 2.0*(1.0 - na.r)*(1.0 - nb.r),
nb.g <= 0.5? 2*na.g * nb.g : 1.0 - 2.0*(1.0 - na.g)*(1.0 - nb.g),
nb.b <= 0.5? 2*na.b * nb.b : 1.0 - 2.0*(1.0 - na.b)*(1.0 - nb.b)
nb.r <= 0.5? 2.0*na.r * nb.r : 1.0 - 2.0*(1.0 - na.r)*(1.0 - nb.r),
nb.g <= 0.5? 2.0*na.g * nb.g : 1.0 - 2.0*(1.0 - na.g)*(1.0 - nb.g),
nb.b <= 0.5? 2.0*na.b * nb.b : 1.0 - 2.0*(1.0 - na.b)*(1.0 - nb.b)
);

vec4 result;
Expand Down
6 changes: 3 additions & 3 deletions orx-fx/src/shaders/glsl/blend/normal.frag
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ void main() {
vec4 b = texture2D(tex1, v_texCoord0);
#endif

float alpha = min(1,max(0, b.a));
float alpha = min(1.0, max(0.0, b.a));

vec4 result;
if (!clip) {
result = a * (1.0-alpha) + b;
result = a * (1.0 - alpha) + b;
result.a = clamp(o_color.a, 0.0, 1.0);
} else {
result = a * (1.0-alpha) + b * a.a;
result = a * (1.0 - alpha) + b * a.a;
}

#ifdef OR_GL_FRAGCOLOR
Expand Down
2 changes: 1 addition & 1 deletion orx-fx/src/shaders/glsl/blend/overlay.frag
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ out vec4 o_color;
#endif

vec3 demul(vec4 c) {
if (c.a == 0) {
if (c.a == 0.0) {
return vec3(0.0);
} else {
return c.rgb / c.a;
Expand Down
4 changes: 2 additions & 2 deletions orx-fx/src/shaders/glsl/blend/subtract.frag
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void main() {
vec4 b = texture2D(tex1, v_texCoord0);
#endif

vec3 na = a.a > 0 ? a.rgb/a.a : vec3(0.0);
vec3 nb = b.a > 0 ? b.rgb/b.a : vec3(0.0);
vec3 na = a.a > 0.0 ? a.rgb/a.a : vec3(0.0);
vec3 nb = b.a > 0.0 ? b.rgb/b.a : vec3(0.0);
vec3 subColor = b.rgb;
vec4 result;
if (clip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() {
float lw = exp( float(-(x*x)) / (2.0 * sigma * sigma) ) ;
vec2 tc = v_texCoord0 + float(x) * blurDirection * s;// * spread;
#ifndef OR_WEBGL2
sum += textureLod(tex0, tc, sourceLevel) * lw;
sum += textureLod(tex0, tc, float(sourceLevel)) * lw;
#else
sum += texture(tex0, tc);
#endif
Expand Down
12 changes: 6 additions & 6 deletions orx-fx/src/shaders/glsl/blur/bloom-downscale.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ void main()
{
float centerWeight = 0.16210282163712664;
vec2 diagonalOffsets = vec2(0.3842896354828526, 1.2048616327242379);
vec4 offsets = vec4(-diagonalOffsets.xy, +diagonalOffsets.xy) / textureSize(tex0, 0).xyxy;
vec4 offsets = vec4(-diagonalOffsets.xy, +diagonalOffsets.xy) / vec2(textureSize(tex0, 0)).xyxy;
float diagonalWeight = 0.2085034734347498;

o_output = textureLod(tex0, v_texCoord0, 0) * centerWeight +
textureLod(tex0, v_texCoord0 + offsets.xy, 0) * diagonalWeight +
textureLod(tex0, v_texCoord0 + offsets.wx, 0) * diagonalWeight +
textureLod(tex0, v_texCoord0 + offsets.zw, 0) * diagonalWeight +
textureLod(tex0, v_texCoord0 + offsets.yz, 0) * diagonalWeight;
o_output = textureLod(tex0, v_texCoord0, 0.0) * centerWeight +
textureLod(tex0, v_texCoord0 + offsets.xy, 0.0) * diagonalWeight +
textureLod(tex0, v_texCoord0 + offsets.wx, 0.0) * diagonalWeight +
textureLod(tex0, v_texCoord0 + offsets.zw, 0.0) * diagonalWeight +
textureLod(tex0, v_texCoord0 + offsets.yz, 0.0) * diagonalWeight;
}
Loading

0 comments on commit e3f5e07

Please sign in to comment.