From 4914755ea88a2f1d165963c1591b12d0056f42ab Mon Sep 17 00:00:00 2001 From: davesmith00000 Date: Sat, 16 Nov 2024 21:09:51 +0000 Subject: [PATCH] Rename Shader to ShaderProgram --- .../effectmaterials/Refraction.scala | 4 ++-- .../src/main/scala/indigo/BootResult.scala | 12 +++++----- .../src/main/scala/indigo/IndigoSandbox.scala | 3 +-- .../src/main/scala/indigo/IndigoShader.scala | 3 +-- .../scala/indigo/gameengine/GameEngine.scala | 24 +++++++++++-------- .../src/main/scala/indigo/package.scala | 2 +- .../main/scala/indigo/shared/Startup.scala | 12 +++++----- .../{Shader.scala => ShaderProgram.scala} | 24 +++++++++---------- .../indigo/shared/shader/ShaderRegister.scala | 2 +- .../shared/shader/StandardShaders.scala | 2 +- .../sandbox/scenes/UltravioletScene.scala | 3 +-- .../scala/com/example/shader/ShaderGame.scala | 4 ++-- 12 files changed, 48 insertions(+), 47 deletions(-) rename indigo/indigo/src/main/scala/indigo/shared/shader/{Shader.scala => ShaderProgram.scala} (89%) diff --git a/indigo/indigo-extras/src/main/scala/indigoextras/effectmaterials/Refraction.scala b/indigo/indigo-extras/src/main/scala/indigoextras/effectmaterials/Refraction.scala index cd15de9b7..764fc43f7 100644 --- a/indigo/indigo-extras/src/main/scala/indigoextras/effectmaterials/Refraction.scala +++ b/indigo/indigo-extras/src/main/scala/indigoextras/effectmaterials/Refraction.scala @@ -10,10 +10,10 @@ import indigo.shared.scenegraph.Blend import indigo.shared.scenegraph.Blending import indigo.shared.shader.BlendShader import indigo.shared.shader.EntityShader -import indigo.shared.shader.Shader import indigo.shared.shader.ShaderData import indigo.shared.shader.ShaderId import indigo.shared.shader.ShaderPrimitive.float +import indigo.shared.shader.ShaderProgram import indigo.shared.shader.UltravioletShader import indigo.shared.shader.Uniform import indigo.shared.shader.UniformBlock @@ -43,7 +43,7 @@ object Refraction: ) ) - val shaders: Set[Shader] = + val shaders: Set[ShaderProgram] = Set(entityShader, blendShader) /** Replicates Indigo's original refraction/distortion layer behaviour diff --git a/indigo/indigo/src/main/scala/indigo/BootResult.scala b/indigo/indigo/src/main/scala/indigo/BootResult.scala index e09f9ba1d..463d124ac 100644 --- a/indigo/indigo/src/main/scala/indigo/BootResult.scala +++ b/indigo/indigo/src/main/scala/indigo/BootResult.scala @@ -1,6 +1,6 @@ package indigo -import indigo.shared.shader.Shader +import indigo.shared.shader.ShaderProgram import indigo.shared.subsystems.SubSystem /** The game bootstrapping process results in a `BootResult`, which only occurs once on initial game load. The boot @@ -16,7 +16,7 @@ final case class BootResult[A, Model]( assets: Set[AssetType], fonts: Set[FontInfo], subSystems: Set[SubSystem[Model]], - shaders: Set[Shader] + shaders: Set[ShaderProgram] ) derives CanEqual { def addAnimations(newAnimations: Set[Animation]): BootResult[A, Model] = @@ -55,13 +55,13 @@ final case class BootResult[A, Model]( def withSubSystems(newSubSystems: SubSystem[Model]*): BootResult[A, Model] = withSubSystems(newSubSystems.toSet) - def addShaders(newShaders: Set[Shader]): BootResult[A, Model] = + def addShaders(newShaders: Set[ShaderProgram]): BootResult[A, Model] = this.copy(shaders = shaders ++ newShaders) - def addShaders(newShaders: Shader*): BootResult[A, Model] = + def addShaders(newShaders: ShaderProgram*): BootResult[A, Model] = addShaders(newShaders.toSet) - def withShaders(newShaders: Set[Shader]): BootResult[A, Model] = + def withShaders(newShaders: Set[ShaderProgram]): BootResult[A, Model] = this.copy(shaders = newShaders) - def withShaders(newShaders: Shader*): BootResult[A, Model] = + def withShaders(newShaders: ShaderProgram*): BootResult[A, Model] = withShaders(newShaders.toSet) } diff --git a/indigo/indigo/src/main/scala/indigo/IndigoSandbox.scala b/indigo/indigo/src/main/scala/indigo/IndigoSandbox.scala index 11259b85f..d65c4af53 100644 --- a/indigo/indigo/src/main/scala/indigo/IndigoSandbox.scala +++ b/indigo/indigo/src/main/scala/indigo/IndigoSandbox.scala @@ -1,6 +1,5 @@ package indigo -import indigo._ import indigo.entry.StandardFrameProcessor import indigo.gameengine.GameEngine import indigo.shared.subsystems.SubSystemsRegister @@ -39,7 +38,7 @@ trait IndigoSandbox[StartUpData, Model] extends GameLauncher[StartUpData, Model, /** A fixed set of custom shaders you will be able to render with */ - def shaders: Set[Shader] + def shaders: Set[ShaderProgram] /** The `setup` function is your only opportunity to do an initial work to set up your game. For example, perhaps one * of your assets was a JSON description of a map or an animation sequence, you could process that now, which is why diff --git a/indigo/indigo/src/main/scala/indigo/IndigoShader.scala b/indigo/indigo/src/main/scala/indigo/IndigoShader.scala index 69d40ad5c..627955518 100644 --- a/indigo/indigo/src/main/scala/indigo/IndigoShader.scala +++ b/indigo/indigo/src/main/scala/indigo/IndigoShader.scala @@ -1,6 +1,5 @@ package indigo -import indigo.* import indigo.entry.StandardFrameProcessor import indigo.gameengine.GameEngine import indigo.shared.shader.library @@ -55,7 +54,7 @@ trait IndigoShader extends GameLauncher[IndigoShaderModel, IndigoShaderModel, Un /** The shader you want to render */ - def shader: Shader + def shader: ShaderProgram private def boot(flags: Map[String, String]): Outcome[BootResult[IndigoShaderModel, IndigoShaderModel]] = val width = flags.get("width").map(_.toInt).getOrElse(config.viewport.width) diff --git a/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala b/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala index 3eaf2f796..a7ad2a6cd 100644 --- a/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala +++ b/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala @@ -27,7 +27,7 @@ import indigo.shared.platform.AssetMapping import indigo.shared.platform.SceneProcessor import indigo.shared.shader.BlendShader import indigo.shared.shader.EntityShader -import indigo.shared.shader.Shader +import indigo.shared.shader.ShaderProgram import indigo.shared.shader.ShaderRegister import indigo.shared.shader.StandardShaders import indigo.shared.shader.UltravioletShader @@ -40,7 +40,7 @@ import scala.concurrent.Future final class GameEngine[StartUpData, GameModel, ViewModel]( fonts: Set[FontInfo], animations: Set[Animation], - shaders: Set[Shader], + shaders: Set[ShaderProgram], initialise: AssetCollection => Dice => Outcome[Startup[StartUpData]], initialModel: StartUpData => Outcome[GameModel], initialViewModel: StartUpData => GameModel => Outcome[ViewModel], @@ -268,7 +268,11 @@ object GameEngine { def registerFonts(fontRegister: FontRegister, fonts: Set[FontInfo]): Unit = fonts.foreach(fontRegister.register) - def registerShaders(shaderRegister: ShaderRegister, shaders: Set[Shader], assetCollection: AssetCollection): Unit = + def registerShaders( + shaderRegister: ShaderRegister, + shaders: Set[ShaderProgram], + assetCollection: AssetCollection + ): Unit = shaders.foreach { case s: EntityShader.Source => shaderRegister.remove(s.id) @@ -299,19 +303,19 @@ object GameEngine { id = external.id, vertex = external.vertex .map(a => extractShaderCode(assetCollection.findTextDataByName(a), "indigo-vertex", a)) - .getOrElse(Shader.defaultVertexProgram), + .getOrElse(ShaderProgram.defaultVertexProgram), fragment = external.fragment .map(a => extractShaderCode(assetCollection.findTextDataByName(a), "indigo-fragment", a)) - .getOrElse(Shader.defaultFragmentProgram), + .getOrElse(ShaderProgram.defaultFragmentProgram), prepare = external.prepare .map(a => extractShaderCode(assetCollection.findTextDataByName(a), "indigo-prepare", a)) - .getOrElse(Shader.defaultPrepareProgram), + .getOrElse(ShaderProgram.defaultPrepareProgram), light = external.light .map(a => extractShaderCode(assetCollection.findTextDataByName(a), "indigo-light", a)) - .getOrElse(Shader.defaultLightProgram), + .getOrElse(ShaderProgram.defaultLightProgram), composite = external.composite .map(a => extractShaderCode(assetCollection.findTextDataByName(a), "indigo-composite", a)) - .getOrElse(Shader.defaultCompositeProgram) + .getOrElse(ShaderProgram.defaultCompositeProgram) ) def externalBlendShaderToSource( @@ -322,10 +326,10 @@ object GameEngine { id = external.id, vertex = external.vertex .map(a => extractShaderCode(assetCollection.findTextDataByName(a), "indigo-vertex", a)) - .getOrElse(Shader.defaultVertexProgram), + .getOrElse(ShaderProgram.defaultVertexProgram), fragment = external.fragment .map(a => extractShaderCode(assetCollection.findTextDataByName(a), "indigo-fragment", a)) - .getOrElse(Shader.defaultFragmentProgram) + .getOrElse(ShaderProgram.defaultFragmentProgram) ) private given CanEqual[Option[String], Option[String]] = CanEqual.derived diff --git a/indigo/indigo/src/main/scala/indigo/package.scala b/indigo/indigo/src/main/scala/indigo/package.scala index b9d0ec3db..a9eae7887 100644 --- a/indigo/indigo/src/main/scala/indigo/package.scala +++ b/indigo/indigo/src/main/scala/indigo/package.scala @@ -183,7 +183,7 @@ val BlendMaterial: shared.materials.BlendMaterial.type = shared.materials.BlendM type ShaderData = shared.shader.ShaderData val ShaderData: shared.shader.ShaderData.type = shared.shader.ShaderData -type Shader = shared.shader.Shader +type ShaderProgram = shared.shader.ShaderProgram type BlendShader = shared.shader.BlendShader val BlendShader: shared.shader.BlendShader.type = shared.shader.BlendShader diff --git a/indigo/indigo/src/main/scala/indigo/shared/Startup.scala b/indigo/indigo/src/main/scala/indigo/shared/Startup.scala index 54dd74997..7b348048d 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/Startup.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/Startup.scala @@ -3,7 +3,7 @@ package indigo.shared import indigo.Batch import indigo.shared.animation.Animation import indigo.shared.datatypes.FontInfo -import indigo.shared.shader.Shader +import indigo.shared.shader.ShaderProgram /** The Startup data type describes either a successful or failed start up sequence. It can hold a value, as well as new * shaders, animations and fonts to be added to Indigo's registers. A new Startup instance is created each time the @@ -28,7 +28,7 @@ sealed trait Startup[+SuccessType] extends Product with Serializable derives Can f } - def additionalShaders: Set[Shader] = + def additionalShaders: Set[ShaderProgram] = this match case Startup.Failure(_) => Set() @@ -52,7 +52,7 @@ object Startup: success: SuccessType, animations: Set[Animation], fonts: Set[FontInfo], - shaders: Set[Shader] + shaders: Set[ShaderProgram] ) extends Startup[SuccessType] derives CanEqual: def addAnimations(value: Animation*): Success[SuccessType] = @@ -69,11 +69,11 @@ object Startup: def addFonts(value: Batch[FontInfo]): Success[SuccessType] = Success(success, animations, fonts ++ value.toSet, shaders) - def addShaders(value: Shader*): Success[SuccessType] = + def addShaders(value: ShaderProgram*): Success[SuccessType] = addShaders(value.toList) - def addShaders(value: List[Shader]): Success[SuccessType] = + def addShaders(value: List[ShaderProgram]): Success[SuccessType] = Success(success, animations, fonts, shaders ++ value) - def addShaders(value: Batch[Shader]): Success[SuccessType] = + def addShaders(value: Batch[ShaderProgram]): Success[SuccessType] = Success(success, animations, fonts, shaders ++ value.toSet) object Success: diff --git a/indigo/indigo/src/main/scala/indigo/shared/shader/Shader.scala b/indigo/indigo/src/main/scala/indigo/shared/shader/ShaderProgram.scala similarity index 89% rename from indigo/indigo/src/main/scala/indigo/shared/shader/Shader.scala rename to indigo/indigo/src/main/scala/indigo/shared/shader/ShaderProgram.scala index 9dbea25e6..059bbf3bc 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/shader/Shader.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/shader/ShaderProgram.scala @@ -8,10 +8,10 @@ import ultraviolet.datatypes.ShaderResult import ultraviolet.syntax.vec4 import ultraviolet.syntax.Shader as UVShader -sealed trait Shader derives CanEqual: +sealed trait ShaderProgram derives CanEqual: def id: ShaderId -object Shader: +object ShaderProgram: val defaultVertexProgram: String = """vec4 vertex(vec4 v){ | return v; @@ -29,7 +29,7 @@ object Shader: val defaultCompositeProgram: String = """void composite(){}""" -final case class UltravioletShader(id: ShaderId, vertex: ShaderResult, fragment: ShaderResult) extends Shader +final case class UltravioletShader(id: ShaderId, vertex: ShaderResult, fragment: ShaderResult) extends ShaderProgram object UltravioletShader: inline def noopVertex: UVShader[IndigoUV.VertexEnv, Unit] = @@ -52,7 +52,7 @@ object UltravioletShader: fragment ) -sealed trait EntityShader extends Shader +sealed trait EntityShader extends ShaderProgram object EntityShader extends BaseEntityShader: final case class Source( @@ -86,11 +86,11 @@ object EntityShader extends BaseEntityShader: def apply(id: ShaderId): Source = Source( id, - Shader.defaultVertexProgram, - Shader.defaultFragmentProgram, - Shader.defaultPrepareProgram, - Shader.defaultLightProgram, - Shader.defaultCompositeProgram + ShaderProgram.defaultVertexProgram, + ShaderProgram.defaultFragmentProgram, + ShaderProgram.defaultPrepareProgram, + ShaderProgram.defaultLightProgram, + ShaderProgram.defaultCompositeProgram ) final case class External( @@ -131,7 +131,7 @@ object EntityShader extends BaseEntityShader: None ) -sealed trait BlendShader extends Shader +sealed trait BlendShader extends ShaderProgram object BlendShader extends BaseBlendShader: final case class Source( @@ -153,8 +153,8 @@ object BlendShader extends BaseBlendShader: def apply(id: ShaderId): Source = Source( id, - Shader.defaultVertexProgram, - Shader.defaultFragmentProgram + ShaderProgram.defaultVertexProgram, + ShaderProgram.defaultFragmentProgram ) final case class External( diff --git a/indigo/indigo/src/main/scala/indigo/shared/shader/ShaderRegister.scala b/indigo/indigo/src/main/scala/indigo/shared/shader/ShaderRegister.scala index bc2dd179e..be0befc9e 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/shader/ShaderRegister.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/shader/ShaderRegister.scala @@ -10,7 +10,7 @@ final class ShaderRegister: def kill(): Unit = clearRegister() - def register(shader: Shader): Unit = + def register(shader: ShaderProgram): Unit = shader match case s: EntityShader.Source => registerEntityShader(s) diff --git a/indigo/indigo/src/main/scala/indigo/shared/shader/StandardShaders.scala b/indigo/indigo/src/main/scala/indigo/shared/shader/StandardShaders.scala index 8ca20382e..e98903ed1 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/shader/StandardShaders.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/shader/StandardShaders.scala @@ -4,7 +4,7 @@ import indigo.shared.shader.library object StandardShaders { - def all: Set[Shader] = + def all: Set[ShaderProgram] = Set( Bitmap, LitBitmap, diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/UltravioletScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/UltravioletScene.scala index 3930cc30f..404077e4c 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/UltravioletScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/UltravioletScene.scala @@ -7,6 +7,7 @@ import com.example.sandbox.SandboxView import com.example.sandbox.SandboxViewModel import indigo.* import indigo.scenes.* +import ultraviolet.syntax.* object UltravioletScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxViewModel] { @@ -66,8 +67,6 @@ case object MakeRedBlend extends BlendMaterial derives CanEqual { object UVShaders: - import ultraviolet.syntax.* - // Blend inline def makeRedder: Shader[BlendFragmentEnv, Unit] = diff --git a/indigo/shader/src/main/scala/com/example/shader/ShaderGame.scala b/indigo/shader/src/main/scala/com/example/shader/ShaderGame.scala index 859d009c7..7a7f3c85c 100644 --- a/indigo/shader/src/main/scala/com/example/shader/ShaderGame.scala +++ b/indigo/shader/src/main/scala/com/example/shader/ShaderGame.scala @@ -12,7 +12,7 @@ object ShaderGame extends IndigoShader: val channel2: Option[AssetPath] = None val channel3: Option[AssetPath] = None - val shader: Shader = + val shader: ShaderProgram = // ShowImage.shader SeascapeShader.shader @@ -49,7 +49,7 @@ object SeascapeShader: object VoronoiShader: - val shader: Shader = + val shader: ShaderProgram = UltravioletShader.entityFragment( ShaderId("my shader"), EntityShader.fragment[FragmentEnv](voronoi, FragmentEnv.reference)