Skip to content

Commit

Permalink
Rename Shader to ShaderProgram
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 17, 2024
1 parent 257523f commit 4914755
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions indigo/indigo/src/main/scala/indigo/BootResult.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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] =
Expand Down Expand Up @@ -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)

}
Expand Down
3 changes: 1 addition & 2 deletions indigo/indigo/src/main/scala/indigo/IndigoSandbox.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package indigo

import indigo._
import indigo.entry.StandardFrameProcessor
import indigo.gameengine.GameEngine
import indigo.shared.subsystems.SubSystemsRegister
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions indigo/indigo/src/main/scala/indigo/IndigoShader.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package indigo

import indigo.*
import indigo.entry.StandardFrameProcessor
import indigo.gameengine.GameEngine
import indigo.shared.shader.library
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 14 additions & 10 deletions indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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],
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion indigo/indigo/src/main/scala/indigo/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions indigo/indigo/src/main/scala/indigo/shared/Startup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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] =
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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] =
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import indigo.shared.shader.library

object StandardShaders {

def all: Set[Shader] =
def all: Set[ShaderProgram] =
Set(
Bitmap,
LitBitmap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] {

Expand Down Expand Up @@ -66,8 +67,6 @@ case object MakeRedBlend extends BlendMaterial derives CanEqual {

object UVShaders:

import ultraviolet.syntax.*

// Blend

inline def makeRedder: Shader[BlendFragmentEnv, Unit] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4914755

Please sign in to comment.