The Skung Rockification of Ziggy Skungdust and the SIMD's

This commit is contained in:
2024-05-13 01:11:03 +10:00
parent b62cd056b5
commit 6c44476062
40 changed files with 2066 additions and 386 deletions

View File

@ -1,3 +1,4 @@
import Maths
import OpenGL
@ -308,23 +309,28 @@ struct OpenGLState
}
}
enum CullFace { case front, back, frontAndBack }
private var _cullFace: CullFace = .back
enum Face { case front, back, frontAndBack }
private var _cullFace: Face = .back
var cullFace: CullFace
fileprivate func glFace(_ face: Face) -> GLenum
{
let face = switch face
{
case .front: GL_FRONT
case .back: GL_BACK
case .frontAndBack: GL_FRONT_AND_BACK
}
return GLenum(face)
}
var cullFace: Face
{
get { _cullFace }
set(newMode)
{
if newMode != _cullFace
{
let modeEnum = switch newMode
{
case .front: GL_FRONT
case .back: GL_BACK
case .frontAndBack: GL_FRONT_AND_BACK
}
glCullFace(GLenum(modeEnum))
glCullFace(glFace(newMode))
_cullFace = newMode
}
}
@ -815,4 +821,97 @@ struct OpenGLState
}
}
}
private var _materialAmbient = Colour(r: 0.2, g: 0.2, b: 0.2)
private var _materialDiffuse = Colour(r: 0.8, g: 0.8, b: 0.8)
private var _materialSpecular = Colour.black
private var _materialEmmision = Colour.black
fileprivate func setMaterialColour(_ face: Face, _ pname: Int32, _ colour: Colour)
{
let face = glFace(.frontAndBack)
if _capabilities.contains(.colourMaterial)
{
glColorMaterial(face, GLenum(pname))
glColor4f(colour.r, colour.g, colour.b, colour.a)
}
else
{
withUnsafePointer(to: colour)
{
$0.withMemoryRebound(to: GLfloat.self, capacity: 4)
{
glMaterialfv(face, GLenum(pname), $0)
}
}
}
}
var materialAmbient: Colour
{
get { _materialAmbient }
set(newColour)
{
if newColour != _materialAmbient
{
setMaterialColour(.frontAndBack, GL_AMBIENT, newColour)
_materialAmbient = newColour
}
}
}
var materialDiffuse: Colour
{
get { _materialDiffuse }
set(newColour)
{
if newColour != _materialDiffuse
{
setMaterialColour(.frontAndBack, GL_DIFFUSE, newColour)
_materialDiffuse = newColour
}
}
}
var materialSpecular: Colour
{
get { _materialSpecular }
set(newColour)
{
if newColour != _materialSpecular
{
setMaterialColour(.frontAndBack, GL_SPECULAR, newColour)
_materialSpecular = newColour
}
}
}
var materialEmmision: Colour
{
get { _materialEmmision }
set(newColour)
{
if newColour != _materialEmmision
{
setMaterialColour(.frontAndBack, GL_EMISSION, newColour)
_materialEmmision = newColour
}
}
}
private var _materialShininess: Float = 0
var materialShininess: Float
{
get { _materialShininess }
set(newParam)
{
if newParam != _materialShininess
{
let face = glFace(.frontAndBack)
glMaterialf(face, GLenum(GL_SHININESS), newParam)
_materialShininess = newParam
}
}
}
}