mirror of
https://github.com/ScrelliCopter/NeHe-SDL_GPU.git
synced 2025-06-19 21:49:17 +10:00
Simplify lessons that use textured shaders w/o tinting
This commit is contained in:
@@ -298,11 +298,8 @@ struct Lesson10: AppDelegate
|
||||
modelView.translate(-camera.position)
|
||||
|
||||
// Push shader uniforms
|
||||
struct Uniforms { var modelViewProj: simd_float4x4, color: SIMD4<Float> }
|
||||
var u = Uniforms(
|
||||
modelViewProj: self.projection * modelView,
|
||||
color: .init(repeating: 1.0))
|
||||
SDL_PushGPUVertexUniformData(cmd, 0, &u, UInt32(MemoryLayout<Uniforms>.size))
|
||||
var modelViewProj = self.projection * modelView
|
||||
SDL_PushGPUVertexUniformData(cmd, 0, &modelViewProj, UInt32(MemoryLayout<simd_float4x4>.size))
|
||||
|
||||
// Draw world
|
||||
SDL_DrawGPUPrimitives(pass, UInt32(self.world.vertices.count), 1, 0, 0)
|
||||
|
||||
@@ -209,8 +209,6 @@ struct Lesson6: AppDelegate
|
||||
vtxBindings.withUnsafeBufferPointer(\.baseAddress!), UInt32(vtxBindings.count))
|
||||
SDL_BindGPUIndexBuffer(pass, &idxBinding, SDL_GPU_INDEXELEMENTSIZE_16BIT)
|
||||
|
||||
struct Uniforms { var modelViewProj: simd_float4x4, color: SIMD4<Float> }
|
||||
|
||||
// Move cube 5 units into the camera and apply some rotations
|
||||
var model: simd_float4x4 = .translation(.init(0.0, 0.0, -5.0))
|
||||
model.rotate(angle: rot.x, axis: .init(1.0, 0.0, 0.0))
|
||||
@@ -218,10 +216,8 @@ struct Lesson6: AppDelegate
|
||||
model.rotate(angle: rot.z, axis: .init(0.0, 0.0, 1.0))
|
||||
|
||||
// Push shader uniforms
|
||||
var u = Uniforms(
|
||||
modelViewProj: self.projection * model,
|
||||
color: .init(repeating: 1.0))
|
||||
SDL_PushGPUVertexUniformData(cmd, 0, &u, UInt32(MemoryLayout<Uniforms>.size))
|
||||
var modelViewProj = self.projection * model
|
||||
SDL_PushGPUVertexUniformData(cmd, 0, &modelViewProj, UInt32(MemoryLayout<matrix_float4x4>.size))
|
||||
|
||||
// Draw textured cube
|
||||
SDL_DrawGPUIndexedPrimitives(pass, UInt32(Self.indices.count), 1, 0, 0, 0)
|
||||
|
||||
@@ -266,11 +266,8 @@ struct Lesson7: AppDelegate
|
||||
}
|
||||
else
|
||||
{
|
||||
struct Uniforms { var modelViewProj: simd_float4x4, color: SIMD4<Float> }
|
||||
var u = Uniforms(
|
||||
modelViewProj: self.projection * model,
|
||||
color: .init(repeating: 1.0))
|
||||
SDL_PushGPUVertexUniformData(cmd, 0, &u, UInt32(MemoryLayout<Uniforms>.size))
|
||||
var modelViewProj = self.projection * model
|
||||
SDL_PushGPUVertexUniformData(cmd, 0, &modelViewProj, UInt32(MemoryLayout<simd_float4x4>.size))
|
||||
}
|
||||
|
||||
// Draw textured cube
|
||||
|
||||
@@ -90,7 +90,7 @@ struct Lesson8: AppDelegate
|
||||
|
||||
mutating func `init`(ctx: inout NeHeContext) throws(NeHeError)
|
||||
{
|
||||
let (vertexShaderUnlit, fragmentShaderUnlit) = try ctx.loadShaders(name: "lesson6",
|
||||
let (vertexShaderUnlit, fragmentShaderUnlit) = try ctx.loadShaders(name: "lesson8",
|
||||
vertexUniforms: 1, fragmentSamplers: 1)
|
||||
defer
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user