Mercurial > games > semicongine
changeset 1138:02e1d2658ff5
did: more renaming
line wrap: on
line diff
--- a/semicongine/algorithms.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/algorithms.nim Tue Jun 04 22:08:48 2024 +0700 @@ -46,7 +46,7 @@ return (false, newRect) -proc pack*[T: Pixel](images: seq[Image[T]]): tuple[atlas: Image[T], coords: seq[tuple[x: uint32, y: uint32]]] = +proc Pack*[T: Pixel](images: seq[Image[T]]): tuple[atlas: Image[T], coords: seq[tuple[x: uint32, y: uint32]]] = const MAX_ATLAS_SIZE = 4096'u32 var areas: seq[tuple[i: int, w, h: uint32]]
--- a/semicongine/animation.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/animation.nim Tue Jun 04 22:08:48 2024 +0700 @@ -83,10 +83,10 @@ else: return combine(EASEFUNC_MAP[keyframe.easeIn], makeEaseOut(EASEFUNC_MAP[keyframe.easeOut]))(t) -func keyframe*[T](timestamp: AnimationTime, value: T, easeIn = Linear, easeOut = None): Keyframe[T] = +func InitKeyframe*[T](timestamp: AnimationTime, value: T, easeIn = Linear, easeOut = None): Keyframe[T] = Keyframe[T](timestamp: timestamp, value: value, easeIn: easeIn, easeOut: easeOut) -func newAnimation*[T](keyframes: openArray[Keyframe[T]], duration: float32, direction = Forward, iterations = 1): Animation[T] = +func NewAnimation*[T](keyframes: openArray[Keyframe[T]], duration: float32, direction = Forward, iterations = 1): Animation[T] = assert keyframes.len >= 2, "An animation needs at least 2 keyframes" assert keyframes[0].timestamp == 0, "An animation's first keyframe needs to have timestamp=0" assert keyframes[^1].timestamp == 1, "An animation's last keyframe needs to have timestamp=1" @@ -119,7 +119,7 @@ iterations: iterations ) -func newAnimation*[T](fun: (state: AnimationState[T], dt: float32) -> T, duration: float32, direction = Forward, iterations = 1): Animation[T] = +func NewAnimation*[T](fun: (state: AnimationState[T], dt: float32) -> T, duration: float32, direction = Forward, iterations = 1): Animation[T] = assert fun != nil, "Animation function cannot be nil" Animation[T]( animationFunction: fun, @@ -128,7 +128,7 @@ iterations: iterations ) -proc resetState*[T](state: var AnimationState[T], initial: T) = +proc ResetState*[T](state: var AnimationState[T], initial: T) = state.currentValue = initial state.currentTime = 0 state.currentDirection = if state.animation.direction == Backward: -1 else: 1 @@ -137,20 +137,20 @@ proc t*(state: AnimationState): AnimationTime = max(low(AnimationTime), min(state.currentTime / state.animation.duration, high(AnimationTime))) -proc newAnimationState*[T](animation: Animation[T], initial = default(T)): AnimationState[T] = +proc NewAnimationState*[T](animation: Animation[T], initial = default(T)): AnimationState[T] = result = AnimationState[T](animation: animation, playing: false) result.resetState(initial) -proc newAnimationState*[T](value: T = default(T)): AnimationState[T] = - newAnimationState[T](newAnimation[T]((state: AnimationState[T], dt: float32) => value, 0), initial = value) +proc NewAnimationState*[T](value: T = default(T)): AnimationState[T] = + NewAnimationState[T](NewAnimation[T]((state: AnimationState[T], dt: float32) => value, 0), initial = value) -func start*(state: var AnimationState) = +func Start*(state: var AnimationState) = state.playing = true -func stop*(state: var AnimationState) = +func Stop*(state: var AnimationState) = state.playing = false -proc advance*[T](state: var AnimationState[T], dt: float32): T = +proc Advance*[T](state: var AnimationState[T], dt: float32): T = # TODO: check this function, not 100% correct I think if state.playing: state.currentTime += float32(state.currentDirection) * dt
--- a/semicongine/audio.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/audio.nim Tue Jun 04 22:08:48 2024 +0700 @@ -58,7 +58,7 @@ mixer.buffers.add newSeq[Sample](BUFFERSAMPLECOUNT) for i in 0 ..< mixer.buffers.len: bufferaddresses.add (addr mixer.buffers[i]) - mixer.device = openSoundDevice(AUDIO_SAMPLE_RATE, bufferaddresses) + mixer.device = OpenSoundDevice(AUDIO_SAMPLE_RATE, bufferaddresses) proc LoadSound*(mixer: var Mixer, name: string, resource: string) = assert not (name in mixer.sounds) @@ -237,7 +237,7 @@ track.playing.del(id) mixer.buffers[mixer.currentBuffer][i] = mixedSample # send data to sound device - mixer.device.writeSoundData(mixer.currentBuffer) + mixer.device.WriteSoundData(mixer.currentBuffer) mixer.currentBuffer = (mixer.currentBuffer + 1) mod mixer.buffers.len # DSP functions @@ -279,7 +279,7 @@ proc destroy(mixer: var Mixer) = mixer.lock.deinitLock() - mixer.device.closeSoundDevice() + mixer.device.CloseSoundDevice() # Threaded implementation, usually used for audio
--- a/semicongine/collision.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/collision.nim Tue Jun 04 22:08:48 2024 +0700 @@ -16,7 +16,7 @@ func between(value, b1, b2: float32): bool = min(b1, b2) <= value and value <= max(b1, b2) -func contains*(collider: Collider, x: Vec3f): bool = +func Contains*(collider: Collider, x: Vec3f): bool = # from https://math.stackexchange.com/questions/1472049/check-if-a-point-is-inside-a-rectangular-shaped-area-3d case collider.theType: of Box: @@ -311,7 +311,7 @@ result = (normal: NewVec3f(minNormal.x, minNormal.y), penetrationDepth: minDistance + 0.001'f32) -func intersects*(a, b: Collider, as2D = false): bool = +func Intersects*(a, b: Collider, as2D = false): bool = var support = supportPoint(a, b, NewVec3f(0.8153, -0.4239, if as2D: 0.0 else: 0.5786)) # just random initial vector simplex = newSeq[Vec3f]() @@ -330,7 +330,7 @@ direction[0] = 0.0001 inc n -func collision*(a, b: Collider, as2D = false): tuple[hasCollision: bool, normal: Vec3f, penetrationDepth: float32] = +func Collision*(a, b: Collider, as2D = false): tuple[hasCollision: bool, normal: Vec3f, penetrationDepth: float32] = var support = supportPoint(a, b, NewVec3f(0.8153, -0.4239, if as2D: 0.0 else: 0.5786)) # just random initial vector simplex = newSeq[Vec3f]() @@ -350,7 +350,7 @@ direction[0] = 0.0001 inc n -func calculateCollider*(points: openArray[Vec3f], theType: ColliderType): Collider = +func CalculateCollider*(points: openArray[Vec3f], theType: ColliderType): Collider = var minX = high(float32) maxX = low(float32)
--- a/semicongine/core/dynamic_arrays.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/core/dynamic_arrays.nim Tue Jun 04 22:08:48 2024 +0700 @@ -59,7 +59,7 @@ func Size*(value: DataList): uint64 = value.theType.Size * value.len.uint64 -func Hash*(value: DataList): Hash = +func hash*(value: DataList): Hash = case value.theType of Float32: hash(value.float32) of Float64: hash(value.float64)
--- a/semicongine/engine.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/engine.nim Tue Jun 04 22:08:48 2024 +0700 @@ -47,7 +47,7 @@ # forward declarations func GetAspectRatio*(engine: Engine): float32 -proc destroy*(engine: var Engine) = +proc Destroy*(engine: var Engine) = checkVkResult engine.device.vk.vkDeviceWaitIdle() if engine.renderer.isSome: engine.renderer.get.destroy() @@ -60,7 +60,7 @@ SteamShutdown() -proc initEngine*( +proc InitEngine*( applicationName = querySetting(projectName), showFps = DEBUG, vulkanVersion = VK_MAKE_API_VERSION(0, 1, 3, 0), @@ -107,7 +107,7 @@ ) StartMixerThread() -proc initRenderer*( +proc InitRenderer*( engine: var Engine, shaders: openArray[(MaterialType, ShaderConfiguration)], clearColor = NewVec4f(0, 0, 0, 0), @@ -124,7 +124,7 @@ allShaders.add (PANEL_MATERIAL_TYPE, PANEL_SHADER) if not shaders.mapIt(it[0]).contains(TEXT_MATERIAL_TYPE): allShaders.add (TEXT_MATERIAL_TYPE, TEXT_SHADER) - engine.renderer = some(engine.device.initRenderer( + engine.renderer = some(engine.device.InitRenderer( shaders = allShaders, clearColor = clearColor, backFaceCulling = backFaceCulling, @@ -132,12 +132,12 @@ inFlightFrames = inFlightFrames, )) -proc initRenderer*(engine: var Engine, clearColor = NewVec4f(0, 0, 0, 0), vSync = false) = +proc InitRenderer*(engine: var Engine, clearColor = NewVec4f(0, 0, 0, 0), vSync = false) = checkVkResult engine.device.vk.vkDeviceWaitIdle() - engine.initRenderer(@[], clearColor, vSync = vSync) + engine.InitRenderer(@[], clearColor, vSync = vSync) checkVkResult engine.device.vk.vkDeviceWaitIdle() -proc loadScene*(engine: var Engine, scene: var Scene) = +proc LoadScene*(engine: var Engine, scene: var Scene) = debug &"start loading scene '{scene.name}'" assert engine.renderer.isSome assert not scene.loaded @@ -149,12 +149,12 @@ checkVkResult engine.device.vk.vkDeviceWaitIdle() debug &"done loading scene '{scene.name}'" -proc unloadScene*(engine: var Engine, scene: Scene) = +proc UnLoadScene*(engine: var Engine, scene: Scene) = debug &"unload scene '{scene.name}'" engine.renderer.get.destroy(scene) -proc renderScene*(engine: var Engine, scene: var Scene) = - assert engine.renderer.isSome, "Renderer has not yet been initialized, call 'engine.initRenderer' first" +proc RenderScene*(engine: var Engine, scene: var Scene) = + assert engine.renderer.isSome, "Renderer has not yet been initialized, call 'engine.InitRenderer' first" assert engine.renderer.get.hasScene(scene), &"Scene '{scene.name}' has not been loaded yet" let t0 = getMonoTime()
--- a/semicongine/input.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/input.nim Tue Jun 04 22:08:48 2024 +0700 @@ -121,15 +121,15 @@ proc SaveCurrentActionMapping*() = for name, keys in actionMap.keyActions.pairs: - SystemStorage.store(name, keys, table = "input_mapping_key") + SystemStorage.Store(name, keys, table = "input_mapping_key") for name, buttons in actionMap.mouseActions.pairs: - SystemStorage.store(name, buttons, table = "input_mapping_mouse") + SystemStorage.Store(name, buttons, table = "input_mapping_mouse") proc LoadActionMapping*[T]() = reset(actionMap) - for name in SystemStorage.list(table = "input_mapping_key"): + for name in SystemStorage.List(table = "input_mapping_key"): let action = parseEnum[T](name) - let keys = SystemStorage.load(name, set[Key](), table = "input_mapping_key") + let keys = SystemStorage.Load(name, set[Key](), table = "input_mapping_key") for key in keys: MapAction(action, key)
--- a/semicongine/material.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/material.nim Tue Jun 04 22:08:48 2024 +0700 @@ -17,10 +17,10 @@ attributes: Table[string, DataList] dirtyAttributes: seq[string] -proc hasMatchingAttribute*(materialType: MaterialType, attr: ShaderAttribute): bool = +proc HasMatchingAttribute*(materialType: MaterialType, attr: ShaderAttribute): bool = return materialType.attributes.contains(attr.name) and materialType.attributes[attr.name] == attr.theType -proc hasMatchingAttribute*(material: MaterialData, attr: ShaderAttribute): bool = +proc HasMatchingAttribute*(material: MaterialData, attr: ShaderAttribute): bool = return material.attributes.contains(attr.name) and material.attributes[attr.name].theType == attr.theType template `[]`*(material: MaterialData, attributeName: string): DataList = @@ -43,16 +43,16 @@ if not material.dirtyAttributes.contains(attribute): material.dirtyAttributes.add attribute -func dirtyAttributes*(material: MaterialData): seq[string] = +func DirtyAttributes*(material: MaterialData): seq[string] = material.dirtyAttributes -proc clearDirtyAttributes*(material: var MaterialData) = +proc ClearDirtyAttributes*(material: var MaterialData) = material.dirtyAttributes.reset proc `$`*(materialType: MaterialType): string = return materialType.name -proc assertCanRender*(shader: ShaderConfiguration, materialType: MaterialType) = +proc AssertCanRender*(shader: ShaderConfiguration, materialType: MaterialType) = for attr in shader.inputs: if attr.perInstance: if attr.name in [TRANSFORM_ATTRIB, MATERIALINDEX_ATTRIBUTE]: @@ -132,7 +132,7 @@ vertexAttributes: {"position": Vec3F32}.toTable, instanceAttributes: {TRANSFORM_ATTRIB: Mat4F32}.toTable, ) - EMPTY_SHADER* = createShaderConfiguration( + EMPTY_SHADER* = CreateShaderConfiguration( name = "empty shader", inputs = [ Attr[Mat4](TRANSFORM_ATTRIB, memoryPerformanceHint = PreferFastWrite, perInstance = true),
--- a/semicongine/mesh.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/mesh.nim Tue Jun 04 22:08:48 2024 +0700 @@ -40,7 +40,7 @@ dirtyAttributes: seq[string] Mesh* = ref MeshObject -func material*(mesh: MeshObject): MaterialData = +func Material*(mesh: MeshObject): MaterialData = mesh.material func `material=`*(mesh: var MeshObject, material: MaterialData) = @@ -58,10 +58,10 @@ assert false, &"Mesh '{mesh.name}' is missing required instance attribute '{name}: {theType}' for {material.theType}" mesh.material = material -func instanceCount*(mesh: MeshObject): int = +func InstanceCount*(mesh: MeshObject): int = mesh.instanceTransforms.len -func indicesCount*(mesh: MeshObject): int = +func IndicesCount*(mesh: MeshObject): int = ( case mesh.indexType of None: 0 @@ -72,67 +72,67 @@ func `$`*(mesh: MeshObject): string = if mesh.indexType == None: - &"Mesh('{mesh.name}', vertexCount: {mesh.vertexCount}, instanceCount: {mesh.instanceCount}, vertexData: {mesh.vertexData.keys().toSeq()}, instanceData: {mesh.instanceData.keys().toSeq()}, indexType: {mesh.indexType}, material: {mesh.material})" + &"Mesh('{mesh.name}', vertexCount: {mesh.vertexCount}, instanceCount: {mesh.InstanceCount}, vertexData: {mesh.vertexData.keys().toSeq()}, instanceData: {mesh.instanceData.keys().toSeq()}, indexType: {mesh.indexType}, material: {mesh.material})" else: - &"Mesh('{mesh.name}', vertexCount: {mesh.vertexCount}, indexCount: {mesh.indicesCount}, instanceCount: {mesh.instanceCount}, vertexData: {mesh.vertexData.keys().toSeq()}, instanceData: {mesh.instanceData.keys().toSeq()}, indexType: {mesh.indexType}, material: {mesh.material})" + &"Mesh('{mesh.name}', vertexCount: {mesh.vertexCount}, indexCount: {mesh.IndicesCount}, instanceCount: {mesh.InstanceCount}, vertexData: {mesh.vertexData.keys().toSeq()}, instanceData: {mesh.instanceData.keys().toSeq()}, indexType: {mesh.indexType}, material: {mesh.material})" func `$`*(mesh: Mesh): string = $mesh[] -func vertexAttributes*(mesh: MeshObject): seq[string] = +func VertexAttributes*(mesh: MeshObject): seq[string] = mesh.vertexData.keys.toSeq -func instanceAttributes*(mesh: MeshObject): seq[string] = +func InstanceAttributes*(mesh: MeshObject): seq[string] = mesh.instanceData.keys.toSeq -func attributes*(mesh: MeshObject): seq[string] = - mesh.vertexAttributes & mesh.instanceAttributes +func Attributes*(mesh: MeshObject): seq[string] = + mesh.VertexAttributes & mesh.InstanceAttributes func hash*(mesh: Mesh): Hash = hash(cast[ptr MeshObject](mesh)) -converter toVulkan*(indexType: MeshIndexType): VkIndexType = +converter ToVulkan*(indexType: MeshIndexType): VkIndexType = case indexType: of None: VK_INDEX_TYPE_NONE_KHR of Tiny: VK_INDEX_TYPE_UINT8_EXT of Small: VK_INDEX_TYPE_UINT16 of Big: VK_INDEX_TYPE_UINT32 -proc initVertexAttribute*[T](mesh: var MeshObject, attribute: string, value: seq[T]) = +proc InitVertexAttribute*[T](mesh: var MeshObject, attribute: string, value: seq[T]) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.vertexData[attribute] = InitDataList(thetype = GetDataType[T]()) mesh.vertexData[attribute].SetLen(mesh.vertexCount) mesh.vertexData[attribute] = value -proc initVertexAttribute*[T](mesh: var MeshObject, attribute: string, value: T) = - initVertexAttribute(mesh, attribute, newSeqWith(mesh.vertexCount, value)) -proc initVertexAttribute*[T](mesh: var MeshObject, attribute: string) = - initVertexAttribute(mesh = mesh, attribute = attribute, value = default(T)) -proc initVertexAttribute*(mesh: var MeshObject, attribute: string, datatype: DataType) = +proc InitVertexAttribute*[T](mesh: var MeshObject, attribute: string, value: T) = + InitVertexAttribute(mesh, attribute, newSeqWith(mesh.vertexCount, value)) +proc InitVertexAttribute*[T](mesh: var MeshObject, attribute: string) = + InitVertexAttribute(mesh = mesh, attribute = attribute, value = default(T)) +proc InitVertexAttribute*(mesh: var MeshObject, attribute: string, datatype: DataType) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.vertexData[attribute] = InitDataList(thetype = datatype) mesh.vertexData[attribute].SetLen(mesh.vertexCount) -proc initVertexAttribute*(mesh: var MeshObject, attribute: string, data: DataList) = +proc InitVertexAttribute*(mesh: var MeshObject, attribute: string, data: DataList) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.vertexData[attribute] = data -proc initInstanceAttribute*[T](mesh: var MeshObject, attribute: string, value: seq[T]) = +proc InitInstanceAttribute*[T](mesh: var MeshObject, attribute: string, value: seq[T]) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.instanceData[attribute] = InitDataList(thetype = GetDataType[T]()) - mesh.instanceData[attribute].SetLen(mesh.instanceCount) + mesh.instanceData[attribute].SetLen(mesh.InstanceCount) mesh.instanceData[attribute] = value -proc initInstanceAttribute*[T](mesh: var MeshObject, attribute: string, value: T) = - initInstanceAttribute(mesh, attribute, newSeqWith(mesh.instanceCount, value)) -proc initInstanceAttribute*[T](mesh: var MeshObject, attribute: string) = - initInstanceAttribute(mesh = mesh, attribute = attribute, value = default(T)) -proc initInstanceAttribute*(mesh: var MeshObject, attribute: string, datatype: DataType) = +proc InitInstanceAttribute*[T](mesh: var MeshObject, attribute: string, value: T) = + InitInstanceAttribute(mesh, attribute, newSeqWith(mesh.InstanceCount, value)) +proc InitInstanceAttribute*[T](mesh: var MeshObject, attribute: string) = + InitInstanceAttribute(mesh = mesh, attribute = attribute, value = default(T)) +proc InitInstanceAttribute*(mesh: var MeshObject, attribute: string, datatype: DataType) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.instanceData[attribute] = InitDataList(thetype = datatype) - mesh.instanceData[attribute].SetLen(mesh.instanceCount) -proc initInstanceAttribute*(mesh: var MeshObject, attribute: string, data: DataList) = + mesh.instanceData[attribute].SetLen(mesh.InstanceCount) +proc InitInstanceAttribute*(mesh: var MeshObject, attribute: string, data: DataList) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.instanceData[attribute] = data -proc newMesh*( +proc NewMesh*( positions: openArray[Vec3f], indices: openArray[array[3, uint32|uint16|uint8]], colors: openArray[Vec4f] = [], @@ -167,9 +167,9 @@ transform: transform, ) - result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, positions.toSeq) - if colors.len > 0: result[].initVertexAttribute("color", colors.toSeq) - if uvs.len > 0: result[].initVertexAttribute("uv", uvs.toSeq) + result[].InitVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, positions.toSeq) + if colors.len > 0: result[].InitVertexAttribute("color", colors.toSeq) + if uvs.len > 0: result[].InitVertexAttribute("uv", uvs.toSeq) # assert all indices are valid for i in indices: @@ -189,7 +189,7 @@ result[].bigIndices.add [uint32(tri[0]), uint32(tri[1]), uint32(tri[2])] `material=`(result[], material) -proc newMesh*( +proc NewMesh*( positions: openArray[Vec3f], colors: openArray[Vec4f] = [], uvs: openArray[Vec2f] = [], @@ -198,7 +198,7 @@ material = EMPTY_MATERIAL.initMaterialData(), name: string = "", ): Mesh = - newMesh( + NewMesh( positions = positions, indices = newSeq[array[3, uint16]](), colors = colors, @@ -209,7 +209,7 @@ name = name, ) -func attributeSize*(mesh: MeshObject, attribute: string): uint64 = +func AttributeSize*(mesh: MeshObject, attribute: string): uint64 = if mesh.vertexData.contains(attribute): mesh.vertexData[attribute].Size elif mesh.instanceData.contains(attribute): @@ -217,7 +217,7 @@ else: 0 -func attributeType*(mesh: MeshObject, attribute: string): DataType = +func AttributeType*(mesh: MeshObject, attribute: string): DataType = if mesh.vertexData.contains(attribute): mesh.vertexData[attribute].theType elif mesh.instanceData.contains(attribute): @@ -225,7 +225,7 @@ else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") -func indexSize*(mesh: MeshObject): uint64 = +func IndexSize*(mesh: MeshObject): uint64 = case mesh.indexType of None: 0'u64 of Tiny: uint64(mesh.tinyIndices.len * sizeof(get(genericParams(typeof(mesh.tinyIndices)), 0))) @@ -238,14 +238,14 @@ uint64(sizeof(get(genericParams(typeof(value)), 0)) * value.len) ) -func getRawIndexData*(mesh: MeshObject): (pointer, uint64) = +func GetRawIndexData*(mesh: MeshObject): (pointer, uint64) = case mesh.indexType: of None: raise newException(Exception, "Trying to get index data for non-indexed mesh") of Tiny: rawData(mesh.tinyIndices) of Small: rawData(mesh.smallIndices) of Big: rawData(mesh.bigIndices) -func getPointer*(mesh: var MeshObject, attribute: string): pointer = +func GetPointer*(mesh: var MeshObject, attribute: string): pointer = if mesh.vertexData.contains(attribute): mesh.vertexData[attribute].GetPointer() elif mesh.instanceData.contains(attribute): @@ -253,7 +253,7 @@ else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") -proc getAttribute[T: GPUType|int|uint|float](mesh: MeshObject, attribute: string): ref seq[T] = +proc GetAttribute[T: GPUType|int|uint|float](mesh: MeshObject, attribute: string): ref seq[T] = if mesh.vertexData.contains(attribute): mesh.vertexData[attribute][T] elif mesh.instanceData.contains(attribute): @@ -261,7 +261,7 @@ else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") -proc getAttribute[T: GPUType|int|uint|float](mesh: MeshObject, attribute: string, i: int): T = +proc GetAttribute[T: GPUType|int|uint|float](mesh: MeshObject, attribute: string, i: int): T = if mesh.vertexData.contains(attribute): mesh.vertexData[attribute][i, T] elif mesh.instanceData.contains(attribute): @@ -270,26 +270,26 @@ raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") template `[]`*(mesh: MeshObject, attribute: string, t: typedesc): ref seq[t] = - getAttribute[t](mesh, attribute) + GetAttribute[t](mesh, attribute) template `[]`*(mesh: MeshObject, attribute: string, i: int, t: typedesc): untyped = - getAttribute[t](mesh, attribute, i) + GetAttribute[t](mesh, attribute, i) template `[]=`*[T](mesh: MeshObject, attribute: string, value: seq[T]) = - getAttribute[t](mesh, attribute) + GetAttribute[t](mesh, attribute) template `[]=`*[T](mesh: MeshObject, attribute: string, i: int, value: T) = - getAttribute[t](mesh, attribute, i) + GetAttribute[t](mesh, attribute, i) template `[]`*(mesh: Mesh, attribute: string, t: typedesc): ref seq[t] = mesh[][attribute, t] template `[]`*(mesh: Mesh, attribute: string, i: int, t: typedesc): untyped = mesh[][attribute, i, t] -proc updateAttributeData[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, data: DataList) = +proc UpdateAttributeData[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, data: DataList) = if mesh.vertexData.contains(attribute): assert data.len == mesh.vertexCount assert data.theType == mesh.vertexData[attribute].theType mesh.vertexData[attribute] = data elif mesh.instanceData.contains(attribute): - assert data.len == mesh.instanceCount + assert data.len == mesh.InstanceCount assert data.theType == mesh.instanceData[attribute].theType mesh.instanceData[attribute] = data else: @@ -297,19 +297,19 @@ if not mesh.dirtyAttributes.contains(attribute): mesh.dirtyAttributes.add attribute -proc updateAttributeData[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, data: seq[T]) = +proc UpdateAttributeData[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, data: seq[T]) = if mesh.vertexData.contains(attribute): assert data.len == mesh.vertexCount mesh.vertexData[attribute] = data elif mesh.instanceData.contains(attribute): - assert data.len == mesh.instanceCount + assert data.len == mesh.InstanceCount mesh.instanceData[attribute] = data else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") if not mesh.dirtyAttributes.contains(attribute): mesh.dirtyAttributes.add attribute -proc updateAttributeData[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, i: int, value: T) = +proc UpdateAttributeData[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, i: int, value: T) = if mesh.vertexData.contains(attribute): assert i < mesh.vertexData[attribute].len mesh.vertexData[attribute][i] = value @@ -322,26 +322,26 @@ mesh.dirtyAttributes.add attribute proc `[]=`*[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, data: DataList) = - updateAttributeData[T](mesh, attribute, data) + UpdateAttributeData[T](mesh, attribute, data) proc `[]=`*[T: GPUType|int|uint|float](mesh: Mesh, attribute: string, data: DataList) = - updateAttributeData[t](mesh[], attribute, data) + UpdateAttributeData[t](mesh[], attribute, data) proc `[]=`*[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, data: seq[T]) = - updateAttributeData[T](mesh, attribute, data) + UpdateAttributeData[T](mesh, attribute, data) proc `[]=`*[T: GPUType|int|uint|float](mesh: Mesh, attribute: string, data: seq[T]) = - updateAttributeData[T](mesh[], attribute, data) + UpdateAttributeData[T](mesh[], attribute, data) proc `[]=`*[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, value: T) = - updateAttributeData[T](mesh, attribute, newSeqWith(mesh.vertexCount, value)) + UpdateAttributeData[T](mesh, attribute, newSeqWith(mesh.vertexCount, value)) proc `[]=`*[T: GPUType|int|uint|float](mesh: Mesh, attribute: string, value: T) = - updateAttributeData[T](mesh[], attribute, newSeqWith(mesh.vertexCount, value)) + UpdateAttributeData[T](mesh[], attribute, newSeqWith(mesh.vertexCount, value)) proc `[]=`*[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, i: int, value: T) = - updateAttributeData[T](mesh, attribute, i, value) + UpdateAttributeData[T](mesh, attribute, i, value) proc `[]=`*[T: GPUType|int|uint|float](mesh: Mesh, attribute: string, i: int, value: T) = - updateAttributeData[T](mesh[], attribute, i, value) + UpdateAttributeData[T](mesh[], attribute, i, value) -proc removeAttribute*(mesh: var MeshObject, attribute: string) = +proc RemoveAttribute*(mesh: var MeshObject, attribute: string) = if mesh.vertexData.contains(attribute): mesh.vertexData.del(attribute) elif mesh.instanceData.contains(attribute): @@ -349,14 +349,14 @@ else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") -proc appendIndicesData*(mesh: var MeshObject, v1, v2, v3: int) = +proc AppendIndicesData*(mesh: var MeshObject, v1, v2, v3: int) = case mesh.indexType of None: raise newException(Exception, "Mesh does not support indexed data") of Tiny: mesh.tinyIndices.add([uint8(v1), uint8(v2), uint8(v3)]) of Small: mesh.smallIndices.add([uint16(v1), uint16(v2), uint16(v3)]) of Big: mesh.bigIndices.add([uint32(v1), uint32(v2), uint32(v3)]) -proc updateInstanceTransforms*(mesh: var MeshObject, attribute: string) = +proc UpdateInstanceTransforms*(mesh: var MeshObject, attribute: string) = var currentTransforms: seq[Mat4] if mesh.applyMeshTransformToInstances: currentTransforms = mesh.instanceTransforms.mapIt(mesh.transform * it) @@ -366,7 +366,7 @@ mesh[attribute] = currentTransforms mesh.transformCache = currentTransforms -proc renameAttribute*(mesh: var MeshObject, oldname, newname: string) = +proc RenameAttribute*(mesh: var MeshObject, oldname, newname: string) = if mesh.vertexData.contains(oldname): mesh.vertexData[newname] = mesh.vertexData[oldname] mesh.vertexData.del oldname @@ -376,20 +376,20 @@ else: raise newException(Exception, &"Attribute {oldname} is not defined for mesh {mesh}") -func dirtyAttributes*(mesh: MeshObject): seq[string] = +func DirtyAttributes*(mesh: MeshObject): seq[string] = mesh.dirtyAttributes -proc clearDirtyAttributes*(mesh: var MeshObject) = +proc ClearDirtyAttributes*(mesh: var MeshObject) = mesh.dirtyAttributes.reset -proc setShaderMaterialIndices*(mesh: var MeshObject, shadername: string, values: seq[uint16], attributeName = MATERIALINDEX_ATTRIBUTE) = +proc SetShaderMaterialIndices*(mesh: var MeshObject, shadername: string, values: seq[uint16], attributeName = MATERIALINDEX_ATTRIBUTE) = let indexAttribute = shadername & "_" & attributeName - assert values.len == mesh.instanceCount, &"Mesh {mesh}: While trying to set shader material indices for shader '{shadername}': indices have len {values.len}, but instance count is {mesh.instanceCount}" + assert values.len == mesh.InstanceCount, &"Mesh {mesh}: While trying to set shader material indices for shader '{shadername}': indices have len {values.len}, but instance count is {mesh.InstanceCount}" mesh[indexAttribute] = values # MESH-TOOLS -proc transform*[T: GPUType](mesh: var MeshObject, attribute: string, transform: Mat4) = +proc Transform*[T: GPUType](mesh: var MeshObject, attribute: string, transform: Mat4) = if mesh.vertexData.contains(attribute): for i in 0 ..< mesh.vertexData[attribute].len: mesh.vertexData[attribute][i] = transform * mesh.vertexData[attribute][i, T] @@ -400,26 +400,26 @@ raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") mesh.dirtyAttributes.add attribute -func getMeshPoints*(mesh: MeshObject, positionAttribute = DEFAULT_POSITION_ATTRIBUTE): seq[Vec3f] = +func GetMeshPoints*(mesh: MeshObject, positionAttribute = DEFAULT_POSITION_ATTRIBUTE): seq[Vec3f] = for p in mesh[positionAttribute, Vec3f][]: result.add mesh.transform * p -func getCollider*(mesh: MeshObject, positionAttribute = DEFAULT_POSITION_ATTRIBUTE): Collider = - return mesh.getMeshPoints(positionAttribute).calculateCollider(Points) +func GetCollider*(mesh: MeshObject, positionAttribute = DEFAULT_POSITION_ATTRIBUTE): Collider = + return mesh.GetMeshPoints(positionAttribute).CalculateCollider(Points) -proc asNonIndexedMesh*(mesh: MeshObject): MeshObject = +proc AsNonIndexedMesh*(mesh: MeshObject): MeshObject = if mesh.indexType == None: return mesh result = MeshObject( - vertexCount: mesh.indicesCount, + vertexCount: mesh.IndicesCount, indexType: None, transform: mesh.transform, instanceTransforms: mesh.instanceTransforms, visible: mesh.visible, ) for attribute, datalist in mesh.vertexData.pairs: - result.initVertexAttribute(attribute, datalist.theType) + result.InitVertexAttribute(attribute, datalist.theType) for attribute, datalist in mesh.instanceData.pairs: result.instanceData[attribute] = datalist.Copy() var i = 0 @@ -452,7 +452,7 @@ # GENERATORS ============================================================================ -proc rect*(width = 1'f32, height = 1'f32, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = +proc Rect*(width = 1'f32, height = 1'f32, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = result = Mesh( vertexCount: 4, instanceTransforms: @[Unit4], @@ -468,12 +468,12 @@ pos = @[NewVec3f(-half_w, -half_h), NewVec3f(half_w, -half_h), NewVec3f(half_w, half_h), NewVec3f(-half_w, half_h)] c = ToRGBA(color) - result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) - result[].initVertexAttribute("color", @[c, c, c, c]) - result[].initVertexAttribute("uv", @[NewVec2f(0, 0), NewVec2f(1, 0), NewVec2f(1, 1), NewVec2f(0, 1)]) + result[].InitVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) + result[].InitVertexAttribute("color", @[c, c, c, c]) + result[].InitVertexAttribute("uv", @[NewVec2f(0, 0), NewVec2f(1, 0), NewVec2f(1, 1), NewVec2f(0, 1)]) `material=`(result[], material) -proc tri*(width = 1'f32, height = 1'f32, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = +proc Tri*(width = 1'f32, height = 1'f32, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = result = Mesh( vertexCount: 3, instanceTransforms: @[Unit4], @@ -485,8 +485,8 @@ half_h = height / 2 colorVec = ToRGBA(color) - result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, @[NewVec3f(0, -half_h), NewVec3f(half_w, half_h), NewVec3f(-half_w, half_h)]) - result[].initVertexAttribute("color", @[colorVec, colorVec, colorVec]) + result[].InitVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, @[NewVec3f(0, -half_h), NewVec3f(half_w, half_h), NewVec3f(-half_w, half_h)]) + result[].InitVertexAttribute("color", @[colorVec, colorVec, colorVec]) `material=`(result[], material) proc CircleMesh*(nSegments: int): (seq[Vec3f], seq[array[3, uint16]]) = @@ -499,7 +499,7 @@ result[0].add NewVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY) result[1].add [uint16(0), uint16(i), uint16(i + 1)] -proc circle*(width = 1'f32, height = 1'f32, nSegments = 12, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = +proc Circle*(width = 1'f32, height = 1'f32, nSegments = 12, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = assert nSegments >= 3 result = Mesh( vertexCount: 3 + nSegments, @@ -524,12 +524,12 @@ uv.add NewVec2f(cos(float32(i) * step) * 0.5 + 0.5, sin(float32(i) * step) * 0.5 + 0.5) result[].smallIndices.add [uint16(0), uint16(i), uint16(i + 1)] - result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) - result[].initVertexAttribute("color", col) - result[].initVertexAttribute("uv", uv) + result[].InitVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) + result[].InitVertexAttribute("color", col) + result[].InitVertexAttribute("uv", uv) `material=`(result[], material) -proc circleMesh*(width = 1'f32, height = 1'f32, nSegments = 12): (seq[Vec3f], seq[array[3, uint16]]) = +proc CircleMesh*(width = 1'f32, height = 1'f32, nSegments = 12): (seq[Vec3f], seq[array[3, uint16]]) = assert nSegments >= 3 result[0] = newSeq[Vec3f](3 + nSegments) @@ -543,7 +543,7 @@ result[0][i + 1] = NewVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY) result[1].add [uint16(0), uint16(i), uint16(i + 1)] -proc grid*(columns, rows: uint16, cellSize = 1.0'f32, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = +proc Grid*(columns, rows: uint16, cellSize = 1.0'f32, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = result = Mesh( vertexCount: int((rows + 1) * (columns + 1)), @@ -570,11 +570,11 @@ result[].smallIndices.add [i, i - rows - 2, i - rows - 1] i.inc - result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) - result[].initVertexAttribute("color", col) + result[].InitVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) + result[].InitVertexAttribute("color", col) `material=`(result[], material) -proc mergeMeshData*(a: var Mesh, b: Mesh) = +proc MergeMeshData*(a: var Mesh, b: Mesh) = let originalOffset = a.vertexCount a.vertexCount = a.vertexCount + b.vertexCount assert a.indexType == b.indexType
--- a/semicongine/noise.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/noise.nim Tue Jun 04 22:08:48 2024 +0700 @@ -12,7 +12,7 @@ # with Smootherstep (b - a) * ((weight * (weight * 6.0 - 15.0) + 10.0) * weight * weight * weight) + a; -proc perlin*(pos: Vec2f, seed: int32 = 0): float32 = +proc Perlin*(pos: Vec2f, seed: int32 = 0): float32 = let # grid coordinates around target point topleft = NewVec2f(trunc(pos.x), trunc(pos.y))
--- a/semicongine/panel.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/panel.nim Tue Jun 04 22:08:48 2024 +0700 @@ -62,7 +62,7 @@ proc `$`*(panel: Panel): string = &"Panel {panel.mesh}" -proc refresh*(panel: var Panel) = +proc Refresh*(panel: var Panel) = if not panel.dirty: return @@ -83,7 +83,7 @@ panel.dirty = false -proc initPanel*( +proc InitPanel*( transform = Unit4, color = NewVec4f(1, 1, 1, 1), texture = EMPTY_TEXTURE, @@ -128,27 +128,27 @@ inc instanceCounter result.refresh() -proc color*(panel: Panel): Vec4f = +proc Color*(panel: Panel): Vec4f = panel.mesh.material["color", 0, Vec4f] proc `color=`*(panel: var Panel, value: Vec4f) = if value != panel.color: panel.mesh.material["color", 0] = value -proc horizontalAlignment*(panel: Panel): HorizontalAlignment = +proc HorizontalAlignment*(panel: Panel): HorizontalAlignment = panel.horizontalAlignment proc `horizontalAlignment=`*(panel: var Panel, value: HorizontalAlignment) = if value != panel.horizontalAlignment: panel.horizontalAlignment = value panel.dirty = true -proc verticalAlignment*(panel: Panel): VerticalAlignment = +proc VerticalAlignment*(panel: Panel): VerticalAlignment = panel.verticalAlignment proc `verticalAlignment=`*(panel: var Panel, value: VerticalAlignment) = if value != panel.verticalAlignment: panel.verticalAlignment = value panel.dirty = true -proc contains*(panel: Panel, p: Vec2f, aspectRatio: float32): bool = +proc Contains*(panel: Panel, p: Vec2f, aspectRatio: float32): bool = let cursor = panel.mesh.transform.Inversed * p.ToVec3 p1 = panel.mesh[POSITION_ATTRIB, 0, Vec3f]
--- a/semicongine/platform/linux/audio.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/platform/linux/audio.nim Tue Jun 04 22:08:48 2024 +0700 @@ -1,13 +1,13 @@ import ../../core # alsa API -type +type OpenMode*{.size: sizeof(culong).} = enum SND_PCM_BLOCK = 0x00000000 # added by semicongine, for clarity SND_PCM_NONBLOCK = 0x00000001 StreamMode* {.size: sizeof(cint).} = enum SND_PCM_STREAM_PLAYBACK = 0 - AccessMode*{.size: sizeof(cint).} = enum + AccessMode*{.size: sizeof(cint).} = enum SND_PCM_ACCESS_RW_INTERLEAVED = 3 PCMFormat*{.size: sizeof(cint).} = enum SND_PCM_FORMAT_S16_LE = 2 @@ -15,7 +15,7 @@ snd_pcm_hw_params_p* = ptr object snd_pcm_uframes_t* = culong snd_pcm_sframes_t* = clong -{.pragma: alsafunc, importc, cdecl, dynlib: "libasound.so.2" .} +{.pragma: alsafunc, importc, cdecl, dynlib: "libasound.so.2".} proc snd_pcm_open*(pcm_ref: ptr snd_pcm_p, name: cstring, streamMode: StreamMode, openmode: OpenMode): cint {.alsafunc.} proc snd_pcm_close*(pcm: snd_pcm_p): cint {.alsafunc.} proc snd_pcm_hw_params_malloc*(hw_params_ptr: ptr snd_pcm_hw_params_p): cint {.alsafunc.} @@ -30,7 +30,7 @@ proc snd_pcm_writei*(pcm: snd_pcm_p, buffer: pointer, size: snd_pcm_uframes_t): snd_pcm_sframes_t {.alsafunc.} proc snd_pcm_recover*(pcm: snd_pcm_p, err: cint, silent: cint): cint {.alsafunc.} -template checkAlsaResult*(call: untyped) = +template checkAlsaResult(call: untyped) = let value = call if value < 0: raise newException(Exception, "Alsa error: " & astToStr(call) & @@ -42,8 +42,8 @@ NativeSoundDevice* = object handle: snd_pcm_p buffers: seq[ptr SoundData] - -proc openSoundDevice*(sampleRate: uint32, buffers: seq[ptr SoundData]): NativeSoundDevice = + +proc OpenSoundDevice*(sampleRate: uint32, buffers: seq[ptr SoundData]): NativeSoundDevice = var hw_params: snd_pcm_hw_params_p = nil checkAlsaResult snd_pcm_open(addr result.handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_BLOCK) @@ -59,10 +59,10 @@ snd_pcm_hw_params_free(hw_params) result.buffers = buffers -proc writeSoundData*(soundDevice: NativeSoundDevice, buffer: int) = +proc WriteSoundData*(soundDevice: NativeSoundDevice, buffer: int) = var ret = snd_pcm_writei(soundDevice.handle, addr soundDevice.buffers[buffer][][0], snd_pcm_uframes_t(soundDevice.buffers[buffer][].len)) if ret < 0: checkAlsaResult snd_pcm_recover(soundDevice.handle, cint(ret), 0) -proc closeSoundDevice*(soundDevice: NativeSoundDevice) = +proc CloseSoundDevice*(soundDevice: NativeSoundDevice) = discard snd_pcm_close(soundDevice.handle)
--- a/semicongine/platform/linux/surface.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/platform/linux/surface.nim Tue Jun 04 22:08:48 2024 +0700 @@ -1,7 +1,7 @@ import ../../core import ../../platform/window -proc createNativeSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = +proc CreateNativeSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = assert instance.valid var surfaceCreateInfo = VkXlibSurfaceCreateInfoKHR( sType: VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
--- a/semicongine/platform/linux/window.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/platform/linux/window.nim Tue Jun 04 22:08:48 2024 +0700 @@ -24,7 +24,7 @@ window*: x.Window emptyCursor: Cursor -template checkXlibResult*(call: untyped) = +template checkXlibResult(call: untyped) = let value = call if value == 0: raise newException(Exception, "Xlib error: " & astToStr(call) & @@ -33,7 +33,7 @@ proc XErrorLogger(display: PDisplay, event: PXErrorEvent): cint {.cdecl.} = error &"Xlib: {event[]}" -proc createWindow*(title: string): NativeWindow = +proc CreateWindow*(title: string): NativeWindow = checkXlibResult XInitThreads() let display = XOpenDisplay(nil) if display == nil: @@ -76,10 +76,10 @@ checkXlibResult display.XFreePixmap(pixmap) return NativeWindow(display: display, window: window, emptyCursor: empty_cursor) -proc setTitle*(window: NativeWindow, title: string) = +proc SetTitle*(window: NativeWindow, title: string) = checkXlibResult XSetStandardProperties(window.display, window.window, title, "window", 0, nil, 0, nil) -proc fullscreen*(window: var NativeWindow, enable: bool) = +proc Fullscreen*(window: var NativeWindow, enable: bool) = var wm_state = window.display.XInternAtom("_NET_WM_STATE", 0) wm_fullscreen = window.display.XInternAtom("_NET_WM_STATE_FULLSCREEN", 0) @@ -109,25 +109,25 @@ ) checkXlibResult window.display.XFlush() -proc hideSystemCursor*(window: NativeWindow) = +proc HideSystemCursor*(window: NativeWindow) = checkXlibResult XDefineCursor(window.display, window.window, window.emptyCursor) checkXlibResult window.display.XFlush() -proc showSystemCursor*(window: NativeWindow) = +proc ShowSystemCursor*(window: NativeWindow) = checkXlibResult XUndefineCursor(window.display, window.window) checkXlibResult window.display.XFlush() -proc destroy*(window: NativeWindow) = +proc Destroy*(window: NativeWindow) = checkXlibResult window.display.XFreeCursor(window.emptyCursor) checkXlibResult window.display.XDestroyWindow(window.window) discard window.display.XCloseDisplay() # always returns 0 -proc size*(window: NativeWindow): (int, int) = +proc Size*(window: NativeWindow): (int, int) = var attribs: XWindowAttributes checkXlibResult XGetWindowAttributes(window.display, window.window, addr(attribs)) return (int(attribs.width), int(attribs.height)) -proc pendingEvents*(window: NativeWindow): seq[Event] = +proc PendingEvents*(window: NativeWindow): seq[Event] = var event: XEvent while window.display.XPending() > 0: discard window.display.XNextEvent(addr(event)) @@ -163,7 +163,7 @@ discard -proc getMousePosition*(window: NativeWindow): Option[Vec2f] = +proc GetMousePosition*(window: NativeWindow): Option[Vec2f] = var root: x.Window win: x.Window
--- a/semicongine/platform/windows/audio.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/platform/windows/audio.nim Tue Jun 04 22:08:48 2024 +0700 @@ -5,7 +5,7 @@ import ../../core/audiotypes -template checkWinMMResult*(call: untyped) = +template CheckWinMMResult*(call: untyped) = let value = call if value < 0: raise newException(Exception, "Windows multimedia error: " & astToStr(call) & @@ -15,7 +15,7 @@ handle: HWAVEOUT buffers: seq[WAVEHDR] -proc openSoundDevice*(sampleRate: uint32, buffers: seq[ptr SoundData]): NativeSoundDevice = +proc OpenSoundDevice*(sampleRate: uint32, buffers: seq[ptr SoundData]): NativeSoundDevice = var format = WAVEFORMATEX( wFormatTag: WAVE_FORMAT_PCM, nChannels: 2, @@ -37,12 +37,12 @@ checkWinMMResult waveOutPrepareHeader(result.handle, addr result.buffers[i], UINT(sizeof(WAVEHDR))) checkWinMMResult waveOutWrite(result.handle, addr result.buffers[i], UINT(sizeof(WAVEHDR))) -proc writeSoundData*(soundDevice: var NativeSoundDevice, buffer: int) = +proc WriteSoundData*(soundDevice: var NativeSoundDevice, buffer: int) = while (soundDevice.buffers[buffer].dwFlags and WHDR_DONE) == 0: sleep(1) checkWinMMResult waveOutWrite(soundDevice.handle, addr soundDevice.buffers[buffer], UINT(sizeof(WAVEHDR))) -proc closeSoundDevice*(soundDevice: var NativeSoundDevice) = +proc CloseSoundDevice*(soundDevice: var NativeSoundDevice) = for i in 0 ..< soundDevice.buffers.len: discard waveOutUnprepareHeader(soundDevice.handle, addr soundDevice.buffers[i], UINT(sizeof(WAVEHDR))) waveOutClose(soundDevice.handle)
--- a/semicongine/platform/windows/surface.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/platform/windows/surface.nim Tue Jun 04 22:08:48 2024 +0700 @@ -1,7 +1,7 @@ import ../../core import ../../platform/window -proc createNativeSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = +proc CreateNativeSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = assert instance.valid var surfaceCreateInfo = VkWin32SurfaceCreateInfoKHR( sType: VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
--- a/semicongine/platform/windows/window.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/platform/windows/window.nim Tue Jun 04 22:08:48 2024 +0700 @@ -17,7 +17,7 @@ # sorry, have to use module-global variable to capture windows events var currentEvents: seq[Event] -template checkWin32Result*(call: untyped) = +template CheckWin32Result*(call: untyped) = let value = call if value == 0: raise newException(Exception, "Win32 error: " & astToStr(call) & " returned " & $value) @@ -64,7 +64,7 @@ return DefWindowProc(hwnd, uMsg, wParam, lParam) -proc createWindow*(title: string): NativeWindow = +proc CreateWindow*(title: string): NativeWindow = when DEBUG: AllocConsole() discard stdin.reopen("conIN$", fmRead) @@ -101,12 +101,12 @@ result.g_wpPrev.length = UINT(sizeof(WINDOWPLACEMENT)) discard result.hwnd.ShowWindow(SW_SHOW) -proc setTitle*(window: NativeWindow, title: string) = +proc SetTitle*(window: NativeWindow, title: string) = window.hwnd.SetWindowText(T(title)) # inspired by the one and only, Raymond Chen # https://devblogs.microsoft.com/oldnewthing/20100412-00/?p=14353 -proc fullscreen*(window: var NativeWindow, enable: bool) = +proc Fullscreen*(window: var NativeWindow, enable: bool) = let dwStyle: DWORD = GetWindowLong(window.hwnd, GWL_STYLE) if enable: var mi = MONITORINFO(cbSize: DWORD(sizeof(MONITORINFO))) @@ -118,21 +118,21 @@ SetWindowPlacement(window.hwnd, addr window.g_wpPrev) SetWindowPos(window.hwnd, HWND(0), 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER or SWP_NOOWNERZORDER or SWP_FRAMECHANGED) -proc hideSystemCursor*(window: NativeWindow) = +proc HideSystemCursor*(window: NativeWindow) = discard ShowCursor(false) -proc showSystemCursor*(window: NativeWindow) = +proc ShowSystemCursor*(window: NativeWindow) = discard ShowCursor(true) -proc destroy*(window: NativeWindow) = +proc Destroy*(window: NativeWindow) = discard -proc size*(window: NativeWindow): (int, int) = +proc Size*(window: NativeWindow): (int, int) = var rect: RECT checkWin32Result GetWindowRect(window.hwnd, addr(rect)) (int(rect.right - rect.left), int(rect.bottom - rect.top)) -proc pendingEvents*(window: NativeWindow): seq[Event] = +proc PendingEvents*(window: NativeWindow): seq[Event] = # empty queue currentEvents = newSeq[Event]() var msg: MSG @@ -142,7 +142,7 @@ DispatchMessage(addr(msg)) return currentEvents -proc getMousePosition*(window: NativeWindow): Option[Vec2f] = +proc GetMousePosition*(window: NativeWindow): Option[Vec2f] = var p: POINT let res = GetCursorPos(addr(p)) if res:
--- a/semicongine/renderer.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/renderer.nim Tue Jun 04 22:08:48 2024 +0700 @@ -52,10 +52,10 @@ proc currentFrameCommandBuffer(renderer: Renderer): VkCommandBuffer = renderer.commandBufferPool.buffers[renderer.swapchain.currentInFlight] -proc hasScene*(renderer: Renderer, scene: Scene): bool = +proc HasScene*(renderer: Renderer, scene: Scene): bool = scene in renderer.scenedata -proc initRenderer*( +proc InitRenderer*( device: Device, shaders: openArray[(MaterialType, ShaderConfiguration)], clearColor = NewVec4f(0, 0, 0, 0), @@ -66,30 +66,30 @@ assert device.vk.valid result.device = device - result.renderPass = device.createRenderPass(shaders, clearColor = clearColor, backFaceCulling = backFaceCulling) - let swapchain = device.createSwapchain( + result.renderPass = device.CreateRenderPass(shaders, clearColor = clearColor, backFaceCulling = backFaceCulling) + let swapchain = device.CreateSwapchain( result.renderPass.vk, - device.physicalDevice.getSurfaceFormats().filterSurfaceFormat(), + device.physicalDevice.GetSurfaceFormats().FilterSurfaceFormat(), vSync = vSync, inFlightFrames = inFlightFrames, ) if not swapchain.isSome: raise newException(Exception, "Unable to create swapchain") - result.queue = device.firstGraphicsQueue().get() - result.commandBufferPool = device.createCommandBufferPool(result.queue.family, swapchain.get().inFlightFrames) + result.queue = device.FirstGraphicsQueue().get() + result.commandBufferPool = device.CreateCommandBufferPool(result.queue.family, swapchain.get().inFlightFrames) result.swapchain = swapchain.get() - result.emptyTexture = device.uploadTexture(result.queue, EMPTY_TEXTURE) + result.emptyTexture = device.UploadTexture(result.queue, EMPTY_TEXTURE) func shadersForScene(renderer: Renderer, scene: Scene): seq[(MaterialType, ShaderPipeline)] = for (materialType, shaderPipeline) in renderer.renderPass.shaderPipelines: - if scene.usesMaterial(materialType): + if scene.UsesMaterial(materialType): result.add (materialType, shaderPipeline) func vertexInputsForScene(renderer: Renderer, scene: Scene): seq[ShaderAttribute] = var found: Table[string, ShaderAttribute] for (materialType, shaderPipeline) in renderer.shadersForScene(scene): - for input in shaderPipeline.inputs: + for input in shaderPipeline.Inputs: if found.contains(input.name): assert input.name == found[input.name].name, &"{input.name}: {input.name} != {found[input.name].name}" assert input.theType == found[input.name].theType, &"{input.name}: {input.theType} != {found[input.name].theType}" @@ -99,7 +99,7 @@ result.add input found[input.name] = input -proc setupDrawableBuffers*(renderer: var Renderer, scene: var Scene) = +proc SetupDrawableBuffers*(renderer: var Renderer, scene: var Scene) = assert not (scene in renderer.scenedata) var scenedata = SceneData() @@ -114,10 +114,10 @@ # automatically populate material and tranform attributes for mesh in scene.meshes: - if not (TRANSFORM_ATTRIB in mesh[].attributes): - mesh[].initInstanceAttribute(TRANSFORM_ATTRIB, Unit4) - if not (MATERIALINDEX_ATTRIBUTE in mesh[].attributes): - mesh[].initInstanceAttribute(MATERIALINDEX_ATTRIBUTE, uint16(scenedata.materials[mesh.material.theType].find(mesh.material))) + if not (TRANSFORM_ATTRIB in mesh[].Attributes): + mesh[].InitInstanceAttribute(TRANSFORM_ATTRIB, Unit4) + if not (MATERIALINDEX_ATTRIBUTE in mesh[].Attributes): + mesh[].InitInstanceAttribute(MATERIALINDEX_ATTRIBUTE, uint16(scenedata.materials[mesh.material.theType].find(mesh.material))) # create index buffer if necessary var indicesBufferSize = 0'u64 @@ -131,9 +131,9 @@ # index value alignment required by Vulkan if indicesBufferSize mod indexAlignment != 0: indicesBufferSize += indexAlignment - (indicesBufferSize mod indexAlignment) - indicesBufferSize += mesh[].indexSize + indicesBufferSize += mesh[].IndexSize if indicesBufferSize > 0: - scenedata.indexBuffer = renderer.device.createBuffer( + scenedata.indexBuffer = renderer.device.CreateBuffer( size = indicesBufferSize, usage = [VK_BUFFER_USAGE_INDEX_BUFFER_BIT], requireMappable = false, @@ -160,12 +160,12 @@ # we need to expand the buffer size as well, therefore considering alignment already here as well if perLocationSizes[vertexAttribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT != 0: perLocationSizes[vertexAttribute.memoryPerformanceHint] += VERTEX_ATTRIB_ALIGNMENT - (perLocationSizes[vertexAttribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT) - perLocationSizes[vertexAttribute.memoryPerformanceHint] += mesh[].attributeSize(vertexAttribute.name) + perLocationSizes[vertexAttribute.memoryPerformanceHint] += mesh[].AttributeSize(vertexAttribute.name) # create vertex buffers for memoryPerformanceHint, bufferSize in perLocationSizes.pairs: if bufferSize > 0: - scenedata.vertexBuffers[memoryPerformanceHint] = renderer.device.createBuffer( + scenedata.vertexBuffers[memoryPerformanceHint] = renderer.device.CreateBuffer( size = bufferSize, usage = [VK_BUFFER_USAGE_VERTEX_BUFFER_BIT], requireMappable = memoryPerformanceHint == PreferFastWrite, @@ -181,8 +181,8 @@ for mesh in scene.meshes: for attribute in sceneVertexInputs: scenedata.vertexBufferOffsets[(mesh, attribute.name)] = perLocationOffsets[attribute.memoryPerformanceHint] - if mesh[].attributes.contains(attribute.name): - perLocationOffsets[attribute.memoryPerformanceHint] += mesh[].attributeSize(attribute.name) + if mesh[].Attributes.contains(attribute.name): + perLocationOffsets[attribute.memoryPerformanceHint] += mesh[].AttributeSize(attribute.name) if perLocationOffsets[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT != 0: perLocationOffsets[attribute.memoryPerformanceHint] += VERTEX_ATTRIB_ALIGNMENT - (perLocationOffsets[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT) @@ -190,16 +190,16 @@ var offsets: Table[VkPipeline, seq[(string, MemoryPerformanceHint, uint64)]] for (materialType, shaderPipeline) in sceneShaders: offsets[shaderPipeline.vk] = newSeq[(string, MemoryPerformanceHint, uint64)]() - for attribute in shaderPipeline.inputs: + for attribute in shaderPipeline.Inputs: offsets[shaderPipeline.vk].add (attribute.name, attribute.memoryPerformanceHint, scenedata.vertexBufferOffsets[(mesh, attribute.name)]) # create drawables let indexed = mesh.indexType != MeshIndexType.None var drawable = Drawable( name: mesh.name, - elementCount: if indexed: mesh[].indicesCount else: mesh[].vertexCount, + elementCount: if indexed: mesh[].IndicesCount else: mesh[].vertexCount, bufferOffsets: offsets, - instanceCount: mesh[].instanceCount, + instanceCount: mesh[].InstanceCount, indexed: indexed, ) if indexed: @@ -213,8 +213,8 @@ indexBufferOffset += indexAlignment - (indexBufferOffset mod indexAlignment) drawable.indexBufferOffset = indexBufferOffset drawable.indexType = mesh.indexType - var (pdata, size) = mesh[].getRawIndexData() - scenedata.indexBuffer.setData(renderer.queue, pdata, size, indexBufferOffset) + var (pdata, size) = mesh[].GetRawIndexData() + scenedata.indexBuffer.SetData(renderer.queue, pdata, size, indexBufferOffset) indexBufferOffset += size scenedata.drawables.add (drawable, mesh) @@ -222,22 +222,22 @@ var uploadedTextures: Table[Texture, VulkanTexture] for (materialType, shaderPipeline) in sceneShaders: # gather textures - for textureAttribute in shaderPipeline.samplers: + for textureAttribute in shaderPipeline.Samplers: scenedata.shaderData[shaderPipeline.vk].textures[textureAttribute.name] = newSeq[VulkanTexture]() if scene.shaderGlobals.contains(textureAttribute.name): for textureValue in scene.shaderGlobals[textureAttribute.name][Texture][]: if not uploadedTextures.contains(textureValue): - uploadedTextures[textureValue] = renderer.device.uploadTexture(renderer.queue, textureValue) + uploadedTextures[textureValue] = renderer.device.UploadTexture(renderer.queue, textureValue) scenedata.shaderData[shaderPipeline.vk].textures[textureAttribute.name].add uploadedTextures[textureValue] else: var foundTexture = false - for material in scene.getMaterials(materialType): - if material.hasMatchingAttribute(textureAttribute): + for material in scene.GetMaterials(materialType): + if material.HasMatchingAttribute(textureAttribute): foundTexture = true let value = material[textureAttribute.name, Texture][] assert value.len == 1, &"Mesh material attribute '{textureAttribute.name}' has texture-array, but only single textures are allowed" if not uploadedTextures.contains(value[0]): - uploadedTextures[value[0]] = renderer.device.uploadTexture(renderer.queue, value[0]) + uploadedTextures[value[0]] = renderer.device.UploadTexture(renderer.queue, value[0]) scenedata.shaderData[shaderPipeline.vk].textures[textureAttribute.name].add uploadedTextures[value[0]] assert foundTexture, &"No texture found in shaderGlobals or materials for '{textureAttribute.name}'" let nTextures = scenedata.shaderData[shaderPipeline.vk].textures[textureAttribute.name].len.uint32 @@ -247,11 +247,11 @@ # gather uniform sizes var uniformBufferSize = 0'u64 - for uniform in shaderPipeline.uniforms: + for uniform in shaderPipeline.Uniforms: uniformBufferSize += uniform.Size if uniformBufferSize > 0: for frame_i in 0 ..< renderer.swapchain.inFlightFrames: - scenedata.shaderData[shaderPipeline.vk].uniformBuffers.add renderer.device.createBuffer( + scenedata.shaderData[shaderPipeline.vk].uniformBuffers.add renderer.device.CreateBuffer( size = uniformBufferSize, usage = [VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT], requireMappable = true, @@ -266,9 +266,9 @@ nTextures += descriptor.count if nTextures > 0: poolsizes.add (VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, nTextures * renderer.swapchain.inFlightFrames.uint32) - scenedata.shaderData[shaderPipeline.vk].descriptorPool = renderer.device.createDescriptorSetPool(poolsizes) + scenedata.shaderData[shaderPipeline.vk].descriptorPool = renderer.device.CreateDescriptorSetPool(poolsizes) - scenedata.shaderData[shaderPipeline.vk].descriptorSets = shaderPipeline.setupDescriptors( + scenedata.shaderData[shaderPipeline.vk].descriptorSets = shaderPipeline.SetupDescriptors( scenedata.shaderData[shaderPipeline.vk].descriptorPool, scenedata.shaderData[shaderPipeline.vk].uniformBuffers, scenedata.shaderData[shaderPipeline.vk].textures, @@ -276,18 +276,18 @@ emptyTexture = renderer.emptyTexture, ) for frame_i in 0 ..< renderer.swapchain.inFlightFrames: - scenedata.shaderData[shaderPipeline.vk].descriptorSets[frame_i].writeDescriptorSet() + scenedata.shaderData[shaderPipeline.vk].descriptorSets[frame_i].WriteDescriptorSet() renderer.scenedata[scene] = scenedata -proc updateMeshData*(renderer: var Renderer, scene: var Scene, forceAll = false) = +proc UpdateMeshData*(renderer: var Renderer, scene: var Scene, forceAll = false) = assert scene in renderer.scenedata var addedBarrier = false; for (drawable, mesh) in renderer.scenedata[scene].drawables.mitems: - if mesh[].attributes.contains(TRANSFORM_ATTRIB): - mesh[].updateInstanceTransforms(TRANSFORM_ATTRIB) - let attrs = (if forceAll: mesh[].attributes else: mesh[].dirtyAttributes) + if mesh[].Attributes.contains(TRANSFORM_ATTRIB): + mesh[].UpdateInstanceTransforms(TRANSFORM_ATTRIB) + let attrs = (if forceAll: mesh[].Attributes else: mesh[].DirtyAttributes) for attribute in attrs: # ignore attributes that are not used in this scene if attribute in renderer.scenedata[scene].attributeLocation: @@ -296,31 +296,31 @@ # if we have to do a vkCmdCopyBuffer (not buffer.canMap), then we want to added a barrier to # not infer with the current frame that is being renderer (relevant when we have multiple frames in flight) # (remark: ...I think..., I am pretty new to this sync stuff) - if not renderer.scenedata[scene].vertexBuffers[memoryPerformanceHint].canMap and not addedBarrier: - withSingleUseCommandBuffer(renderer.device, renderer.queue, commandBuffer): + if not renderer.scenedata[scene].vertexBuffers[memoryPerformanceHint].CanMap and not addedBarrier: + WithSingleUseCommandBuffer(renderer.device, renderer.queue, commandBuffer): let barrier = VkMemoryBarrier( sType: VK_STRUCTURE_TYPE_MEMORY_BARRIER, srcAccessMask: [VK_ACCESS_MEMORY_READ_BIT].toBits, dstAccessMask: [VK_ACCESS_MEMORY_WRITE_BIT].toBits, ) - commandBuffer.pipelineBarrier( + commandBuffer.PipelineBarrier( srcStages = [VK_PIPELINE_STAGE_VERTEX_INPUT_BIT], dstStages = [VK_PIPELINE_STAGE_TRANSFER_BIT], memoryBarriers = [barrier] ) addedBarrier = true - renderer.scenedata[scene].vertexBuffers[memoryPerformanceHint].setData( + renderer.scenedata[scene].vertexBuffers[memoryPerformanceHint].SetData( renderer.queue, - mesh[].getPointer(attribute), - mesh[].attributeSize(attribute), + mesh[].GetPointer(attribute), + mesh[].AttributeSize(attribute), renderer.scenedata[scene].vertexBufferOffsets[(mesh, attribute)] ) - mesh[].clearDirtyAttributes() + mesh[].ClearDirtyAttributes() -proc updateUniformData*(renderer: var Renderer, scene: var Scene, forceAll = false) = +proc UpdateUniformData*(renderer: var Renderer, scene: var Scene, forceAll = false) = assert scene in renderer.scenedata - let dirty = scene.dirtyShaderGlobals + let dirty = scene.DirtyShaderGlobals if forceAll: debug "Update uniforms because 'forceAll' was given" @@ -332,8 +332,8 @@ if renderer.scenedata[scene].shaderData[shaderPipeline.vk].uniformBuffers.len > 0: var dirtyMaterialAttribs: seq[string] for material in renderer.scenedata[scene].materials[materialType].mitems: - dirtyMaterialAttribs.add material.dirtyAttributes - material.clearDirtyAttributes() + dirtyMaterialAttribs.add material.DirtyAttributes + material.ClearDirtyAttributes() assert renderer.scenedata[scene].shaderData[shaderPipeline.vk].uniformBuffers[renderer.swapchain.currentInFlight].vk.valid if forceAll: for buffer in renderer.scenedata[scene].shaderData[shaderPipeline.vk].uniformBuffers: @@ -341,7 +341,7 @@ var offset = 0'u64 # loop over all uniforms of the shader-shaderPipeline - for uniform in shaderPipeline.uniforms: + for uniform in shaderPipeline.Uniforms: if dirty.contains(uniform.name) or dirtyMaterialAttribs.contains(uniform.name) or forceAll: # only update uniforms if necessary var value = InitDataList(uniform.theType) if scene.shaderGlobals.hasKey(uniform.name): @@ -350,7 +350,7 @@ else: var foundValue = false for material in renderer.scenedata[scene].materials[materialType]: - if material.hasMatchingAttribute(uniform): + if material.HasMatchingAttribute(uniform): value.AppendValues(material[uniform.name]) foundValue = true assert foundValue, &"Uniform '{uniform.name}' not found in scene shaderGlobals or materials" @@ -365,29 +365,29 @@ # frameInFlight (I think), but we don't track for which frame the shaderglobals are no longer dirty # therefore we have to update the uniform values in all buffers, of all inFlightframes (usually 2) for buffer in renderer.scenedata[scene].shaderData[shaderPipeline.vk].uniformBuffers: - buffer.setData(renderer.queue, value.GetPointer(), value.Size, offset) + buffer.SetData(renderer.queue, value.GetPointer(), value.Size, offset) offset += uniform.Size - scene.clearDirtyShaderGlobals() + scene.ClearDirtyShaderGlobals() -proc startNewFrame*(renderer: var Renderer) = +proc StartNewFrame*(renderer: var Renderer) = # TODO: chance for an infinity-loop? - while not renderer.swapchain.acquireNextFrame(): + while not renderer.swapchain.AcquireNextFrame(): checkVkResult renderer.device.vk.vkDeviceWaitIdle() - let res = renderer.swapchain.recreate() + let res = renderer.swapchain.Recreate() if not res.isSome: raise newException(Exception, "Unable to recreate swapchain") var oldSwapchain = renderer.swapchain renderer.swapchain = res.get() checkVkResult renderer.device.vk.vkDeviceWaitIdle() - oldSwapchain.destroy() + oldSwapchain.Destroy() renderer.nextFrameReady = true -proc render*(renderer: var Renderer, scene: Scene) = +proc Render*(renderer: var Renderer, scene: Scene) = assert scene in renderer.scenedata assert renderer.nextFrameReady, "startNewFrame() must be called before calling render()" # preparation - renderer.currentFrameCommandBuffer.beginRenderCommands(renderer.renderPass, renderer.swapchain.currentFramebuffer(), oneTimeSubmit = true) + renderer.currentFrameCommandBuffer.BeginRenderCommands(renderer.renderPass, renderer.swapchain.CurrentFramebuffer(), oneTimeSubmit = true) # debug output debug "Scene buffers:" @@ -397,7 +397,7 @@ # draw all meshes for (materialType, shaderPipeline) in renderer.renderPass.shaderPipelines: - if scene.usesMaterial(materialType): + if scene.UsesMaterial(materialType): debug &"Start shaderPipeline for '{materialType}'" renderer.currentFrameCommandBuffer.vkCmdBindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, shaderPipeline.vk) renderer.currentFrameCommandBuffer.vkCmdBindDescriptorSets( @@ -410,36 +410,36 @@ nil ) for (drawable, mesh) in renderer.scenedata[scene].drawables.filterIt(it[1].visible and it[1].material.theType == materialType): - drawable.draw(renderer.currentFrameCommandBuffer, vertexBuffers = renderer.scenedata[scene].vertexBuffers, indexBuffer = renderer.scenedata[scene].indexBuffer, shaderPipeline.vk) + drawable.Draw(renderer.currentFrameCommandBuffer, vertexBuffers = renderer.scenedata[scene].vertexBuffers, indexBuffer = renderer.scenedata[scene].indexBuffer, shaderPipeline.vk) # done rendering - renderer.currentFrameCommandBuffer.endRenderCommands() + renderer.currentFrameCommandBuffer.EndRenderCommands() # swap framebuffer - if not renderer.swapchain.swap(renderer.queue, renderer.currentFrameCommandBuffer): - let res = renderer.swapchain.recreate() + if not renderer.swapchain.Swap(renderer.queue, renderer.currentFrameCommandBuffer): + let res = renderer.swapchain.Recreate() if res.isSome: var oldSwapchain = renderer.swapchain renderer.swapchain = res.get() checkVkResult renderer.device.vk.vkDeviceWaitIdle() - oldSwapchain.destroy() + oldSwapchain.Destroy() renderer.swapchain.currentInFlight = (renderer.swapchain.currentInFlight + 1) mod renderer.swapchain.inFlightFrames renderer.nextFrameReady = false -func valid*(renderer: Renderer): bool = +func Valid*(renderer: Renderer): bool = renderer.device.vk.valid -proc destroy*(renderer: var Renderer, scene: Scene) = +proc Destroy*(renderer: var Renderer, scene: Scene) = checkVkResult renderer.device.vk.vkDeviceWaitIdle() var scenedata = renderer.scenedata[scene] for buffer in scenedata.vertexBuffers.mvalues: assert buffer.vk.valid - buffer.destroy() + buffer.Destroy() if scenedata.indexBuffer.vk.valid: assert scenedata.indexBuffer.vk.valid - scenedata.indexBuffer.destroy() + scenedata.indexBuffer.Destroy() var destroyedTextures: seq[VkImage] @@ -447,23 +447,23 @@ for buffer in shaderData.uniformBuffers.mitems: assert buffer.vk.valid - buffer.destroy() + buffer.Destroy() for textures in shaderData.textures.mvalues: for texture in textures.mitems: if not destroyedTextures.contains(texture.image.vk): destroyedTextures.add texture.image.vk - texture.destroy() + texture.Destroy() - shaderData.descriptorPool.destroy() + shaderData.descriptorPool.Destroy() renderer.scenedata.del(scene) -proc destroy*(renderer: var Renderer) = +proc Destroy*(renderer: var Renderer) = for scene in renderer.scenedata.keys.toSeq: - renderer.destroy(scene) + renderer.Destroy(scene) assert renderer.scenedata.len == 0 - renderer.emptyTexture.destroy() - renderer.renderPass.destroy() - renderer.commandBufferPool.destroy() - renderer.swapchain.destroy() + renderer.emptyTexture.Destroy() + renderer.renderPass.Destroy() + renderer.commandBufferPool.Destroy() + renderer.swapchain.Destroy()
--- a/semicongine/resources.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/resources.nim Tue Jun 04 22:08:48 2024 +0700 @@ -176,9 +176,9 @@ proc loadAudio*(path: string, package = DEFAULT_PACKAGE): Sound = if path.splitFile().ext.toLowerAscii == ".au": - loadResource_intern(path, package = package).readAU() + loadResource_intern(path, package = package).ReadAU() elif path.splitFile().ext.toLowerAscii == ".ogg": - loadResource_intern(path, package = package).readVorbis() + loadResource_intern(path, package = package).ReadVorbis() else: raise newException(Exception, "Unsupported audio file type: " & path) @@ -199,13 +199,13 @@ var thename = name if thename == "": thename = path.splitFile().name - loadResource_intern(path, package = package).readTrueType(name, charset & additional_codepoints.toSeq, lineHeightPixels) + loadResource_intern(path, package = package).ReadTrueType(name, charset & additional_codepoints.toSeq, lineHeightPixels) proc loadMeshes*(path: string, defaultMaterial: MaterialType, package = DEFAULT_PACKAGE): seq[MeshTree] = - loadResource_intern(path, package = package).readglTF(defaultMaterial) + loadResource_intern(path, package = package).ReadglTF(defaultMaterial) proc loadFirstMesh*(path: string, defaultMaterial: MaterialType, package = DEFAULT_PACKAGE): Mesh = - loadResource_intern(path, package = package).readglTF(defaultMaterial)[0].toSeq[0] + loadResource_intern(path, package = package).ReadglTF(defaultMaterial)[0].toSeq[0] proc packages*(): seq[string] = modList_intern()
--- a/semicongine/resources/audio.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/resources/audio.nim Tue Jun 04 22:08:48 2024 +0700 @@ -35,7 +35,7 @@ result[1] = result[0] # https://en.wikipedia.org/wiki/Au_file_format -proc readAU*(stream: Stream): Sound = +proc ReadAU*(stream: Stream): Sound = var header: AuHeader for name, value in fieldPairs(header): @@ -64,7 +64,7 @@ proc stb_vorbis_decode_memory(mem: pointer, len: cint, channels: ptr cint, sample_rate: ptr cint, output: ptr ptr cshort): cint {.importc.} proc free(p: pointer) {.importc.} -proc readVorbis*(stream: Stream): Sound = +proc ReadVorbis*(stream: Stream): Sound = var data = stream.readAll() channels: cint
--- a/semicongine/resources/font.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/resources/font.nim Tue Jun 04 22:08:48 2024 +0700 @@ -31,7 +31,7 @@ proc free(p: pointer) {.importc.} -proc readTrueType*(stream: Stream, name: string, codePoints: seq[Rune], lineHeightPixels: float32): Font = +proc ReadTrueType*(stream: Stream, name: string, codePoints: seq[Rune], lineHeightPixels: float32): Font = var indata = stream.readAll() fontinfo: stbtt_fontinfo @@ -87,7 +87,7 @@ free(data) - let packed = pack(images) + let packed = Pack(images) result.fontAtlas = Texture( name: name & "_texture",
--- a/semicongine/resources/image.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/resources/image.nim Tue Jun 04 22:08:48 2024 +0700 @@ -39,7 +39,7 @@ gammaGreen: uint32 # not used yet gammaBlue: uint32 # not used yet -proc readBMP*(stream: Stream): Image[RGBAPixel] = +proc ReadBMP*(stream: Stream): Image[RGBAPixel] = var bitmapFileHeader: BitmapFileHeader dibHeader: DIBHeader @@ -113,7 +113,7 @@ proc free(p: pointer) {.importc.} # for some reason the lodepng pointer can only properly be freed with the native free -proc readPNG*(stream: Stream): Image[RGBAPixel] = +proc ReadPNG*(stream: Stream): Image[RGBAPixel] = let indata = stream.readAll() var w, h: cuint var data: cstring @@ -129,7 +129,7 @@ result = NewImage(width = w, height = h, imagedata = imagedata) -proc toPNG*[T: Pixel](image: Image[T]): seq[uint8] = +proc ToPNG*[T: Pixel](image: Image[T]): seq[uint8] = when T is GrayPixel: let pngType = 0 # hardcoded in lodepng.h else: @@ -155,7 +155,7 @@ result[i] = uint8(pngData[i]) free(pngData) -proc writePNG*[T: Pixel](image: Image[T], filename: string) = +proc WritePNG*[T: Pixel](image: Image[T], filename: string) = let f = filename.open(mode = fmWrite) let data = image.toPNG() let written = f.writeBytes(data, 0, data.len)
--- a/semicongine/resources/mesh.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/resources/mesh.nim Tue Jun 04 22:08:48 2024 +0700 @@ -137,9 +137,9 @@ let imageType = root["images"][imageIndex]["mimeType"].getStr() case imageType of "image/bmp": - result = readBMP(imgData) + result = ReadBMP(imgData) of "image/png": - result = readPNG(imgData) + result = ReadPNG(imgData) else: raise newException(Exception, "Unsupported feature: Load image of type " & imageType) @@ -249,7 +249,7 @@ if result.vertexCount == 0: result.vertexCount = data.len assert data.len == result.vertexCount - result[].initVertexAttribute(attribute.toLowerAscii, data) + result[].InitVertexAttribute(attribute.toLowerAscii, data) if primitiveNode.hasKey("material"): let materialId = primitiveNode["material"].getInt() @@ -267,19 +267,19 @@ tri.add int(entry) if tri.len == 3: # FYI gltf uses counter-clockwise indexing - result[].appendIndicesData(tri[0], tri[1], tri[2]) + result[].AppendIndicesData(tri[0], tri[1], tri[2]) tri.setLen(0) of UInt32: for entry in data[uint32][]: tri.add int(entry) if tri.len == 3: # FYI gltf uses counter-clockwise indexing - result[].appendIndicesData(tri[0], tri[1], tri[2]) + result[].AppendIndicesData(tri[0], tri[1], tri[2]) tri.setLen(0) else: raise newException(Exception, &"Unsupported index data type: {data.thetype}") # TODO: getting from gltf to vulkan system is still messed up somehow, see other TODO - transform[Vec3f](result[], "position", Scale(1, -1, 1)) + Transform[Vec3f](result[], "position", Scale(1, -1, 1)) proc loadNode(root: JsonNode, node: JsonNode, materials: seq[MaterialData], mainBuffer: var seq[uint8]): MeshTree = result = MeshTree() @@ -335,7 +335,7 @@ result.updateTransforms() -proc readglTF*(stream: Stream, defaultMaterial: MaterialType): seq[MeshTree] = +proc ReadglTF*(stream: Stream, defaultMaterial: MaterialType): seq[MeshTree] = var header: glTFHeader data: glTFData
--- a/semicongine/scene.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/scene.nim Tue Jun 04 22:08:48 2024 +0700 @@ -15,25 +15,25 @@ dirtyShaderGlobals: seq[string] loaded*: bool = false -proc add*(scene: var Scene, mesh: MeshObject) = +proc Add*(scene: var Scene, mesh: MeshObject) = assert not scene.loaded, &"Scene {scene.name} has already been loaded, cannot add meshes" var tmp = new Mesh tmp[] = mesh scene.meshes.add tmp -proc add*(scene: var Scene, mesh: Mesh) = +proc Add*(scene: var Scene, mesh: Mesh) = assert not scene.loaded, &"Scene {scene.name} has already been loaded, cannot add meshes" assert not mesh.isNil, "Cannot add a mesh that is 'nil'" scene.meshes.add mesh -proc add*(scene: var Scene, meshes: seq[Mesh]) = +proc Add*(scene: var Scene, meshes: seq[Mesh]) = assert not scene.loaded, &"Scene {scene.name} has already been loaded, cannot add meshes" for mesh in meshes: assert not mesh.isNil, "Cannot add a mesh that is 'nil'" scene.meshes.add meshes # generic way to add objects that have a mesh-attribute -proc add*[T](scene: var Scene, obj: T) = +proc Add*[T](scene: var Scene, obj: T) = assert not scene.loaded, &"Scene {scene.name} has already been loaded, cannot add meshes" for name, value in obj.fieldPairs: when typeof(value) is Mesh: @@ -43,43 +43,43 @@ assert not value.isNil, &"Cannot add a mesh that is 'nil': " & name scene.meshes.add value -proc addShaderGlobalArray*[T](scene: var Scene, name: string, data: openArray[T]) = +proc AddShaderGlobalArray*[T](scene: var Scene, name: string, data: openArray[T]) = assert not scene.loaded, &"Scene {scene.name} has already been loaded, cannot add shader values" scene.shaderGlobals[name] = InitDataList(data) scene.dirtyShaderGlobals.add name -proc addShaderGlobal*[T](scene: var Scene, name: string, data: T) = +proc AddShaderGlobal*[T](scene: var Scene, name: string, data: T) = scene.addShaderGlobalArray(name, [data]) -proc getShaderGlobalArray*[T](scene: Scene, name: string): ref seq[T] = +proc GetShaderGlobalArray*[T](scene: Scene, name: string): ref seq[T] = scene.shaderGlobals[name][T] -proc getShaderGlobal*[T](scene: Scene, name: string): T = - getShaderGlobalArray[T](scene, name)[][0] +proc GetShaderGlobal*[T](scene: Scene, name: string): T = + GetShaderGlobalArray[T](scene, name)[][0] -proc setShaderGlobalArray*[T](scene: var Scene, name: string, value: openArray[T]) = +proc SetShaderGlobalArray*[T](scene: var Scene, name: string, value: openArray[T]) = if scene.shaderGlobals[name, T][] == @value: return scene.shaderGlobals[name] = value if not scene.dirtyShaderGlobals.contains(name): scene.dirtyShaderGlobals.add name -proc setShaderGlobal*[T](scene: var Scene, name: string, value: T) = +proc SetShaderGlobal*[T](scene: var Scene, name: string, value: T) = scene.setShaderGlobalArray(name, [value]) -func dirtyShaderGlobals*(scene: Scene): seq[string] = +func DirtyShaderGlobals*(scene: Scene): seq[string] = scene.dirtyShaderGlobals -proc clearDirtyShaderGlobals*(scene: var Scene) = +proc ClearDirtyShaderGlobals*(scene: var Scene) = scene.dirtyShaderGlobals.reset func hash*(scene: Scene): Hash = hash(scene.name) -func usesMaterial*(scene: Scene, materialType: MaterialType): bool = +func UsesMaterial*(scene: Scene, materialType: MaterialType): bool = return scene.meshes.anyIt(it.material.theType == materialType) -func getMaterials*(scene: Scene, materialType: MaterialType): seq[MaterialData] = +func GetMaterials*(scene: Scene, materialType: MaterialType): seq[MaterialData] = for mesh in scene.meshes: if mesh.material.theType == materialType and (not result.contains(mesh.material)): result.add mesh.material
--- a/semicongine/settings.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/settings.nim Tue Jun 04 22:08:48 2024 +0700 @@ -40,7 +40,7 @@ for ns in walkConfigNamespaces(): result[ns] = ns.getFile().loadConfig() -proc reloadSettings*() = +proc ReloadSettings*() = allsettings = loadAllConfig() proc configStr(key, section, namespace: string): string = @@ -52,7 +52,7 @@ raise newException(Exception, &"Settings {namespace}.{section}.{key} was not found") allsettings[namespace].getSectionValue(section, key) -proc setting*[T: int|float|string](key, section, namespace: string): T = +proc Setting*[T: int|float|string](key, section, namespace: string): T = when T is int: let value = configStr(key, section, namespace) if parseInt(value, result) == 0: @@ -64,7 +64,7 @@ else: result = configStr(key, section, namespace) -proc setting*[T: int|float|string](identifier: string): T = +proc Setting*[T: int|float|string](identifier: string): T = # identifier can be in the form: # {namespace}.{key} # {namespace}.{section}.{key} @@ -74,7 +74,7 @@ if parts.len == 2: result = setting[T](parts[1], "", parts[0]) else: result = setting[T](parts[^1], parts[^2], joinPath(parts[0 .. ^3])) -proc hadConfigUpdate*(): bool = +proc HadConfigUpdate*(): bool = when CONFIGHOTRELOAD == true: result = configUpdates.peek() > 0
--- a/semicongine/storage.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/storage.nim Tue Jun 04 22:08:48 2024 +0700 @@ -39,23 +39,23 @@ value TEXT NOT NULL )""")) -proc store*[T](storageType: StorageType, key: string, value: T, table = DEFAULT_KEY_VALUE_TABLE_NAME) = +proc Store*[T](storageType: StorageType, key: string, value: T, table = DEFAULT_KEY_VALUE_TABLE_NAME) = storageType.ensureExists(table) db[storageType].exec(sql(&"""INSERT INTO {table} VALUES(?, ?) ON CONFLICT(key) DO UPDATE SET value=excluded.value """), key, $$value) -proc load*[T](storageType: StorageType, key: string, default: T, table = DEFAULT_KEY_VALUE_TABLE_NAME): T = +proc Load*[T](storageType: StorageType, key: string, default: T, table = DEFAULT_KEY_VALUE_TABLE_NAME): T = storageType.ensureExists(table) let dbResult = db[storageType].getValue(sql(&"""SELECT value FROM {table} WHERE key = ? """), key) if dbResult == "": return default return to[T](dbResult) -proc list*[T](storageType: StorageType, table = DEFAULT_KEY_VALUE_TABLE_NAME): seq[string] = +proc List*[T](storageType: StorageType, table = DEFAULT_KEY_VALUE_TABLE_NAME): seq[string] = storageType.ensureExists(table) for row in db[storageType].fastRows(sql(&"""SELECT key FROM {table}""")): result.add row[0] -proc purge*(storageType: StorageType) = +proc Purge*(storageType: StorageType) = storageType.path().string.removeFile()
--- a/semicongine/text.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/text.nim Tue Jun 04 22:08:48 2024 +0700 @@ -66,7 +66,7 @@ func `$`*(text: Text): string = "\"" & $text.text[0 ..< min(text.text.len, 16)] & "\"" -proc refresh*(text: var Text) = +proc Refresh*(text: var Text) = if not text.dirty and text.processedText == text.lastRenderedText: return @@ -205,7 +205,7 @@ return result -func text*(text: Text): seq[Rune] = +func Text*(text: Text): seq[Rune] = text.text proc `text=`*(text: var Text, newText: seq[Rune]) = @@ -218,27 +218,27 @@ proc `text=`*(text: var Text, newText: string) = `text=`(text, newText.toRunes) -proc color*(text: Text): Vec4f = +proc Color*(text: Text): Vec4f = text.mesh.material["color", 0, Vec4f] proc `color=`*(text: var Text, value: Vec4f) = if value != text.color: text.mesh.material["color", 0] = value -proc horizontalAlignment*(text: Text): HorizontalAlignment = +proc HorizontalAlignment*(text: Text): HorizontalAlignment = text.horizontalAlignment proc `horizontalAlignment=`*(text: var Text, value: HorizontalAlignment) = if value != text.horizontalAlignment: text.horizontalAlignment = value text.dirty = true -proc verticalAlignment*(text: Text): VerticalAlignment = +proc VerticalAlignment*(text: Text): VerticalAlignment = text.verticalAlignment proc `verticalAlignment=`*(text: var Text, value: VerticalAlignment) = if value != text.verticalAlignment: text.verticalAlignment = value text.dirty = true -proc initText*(font: Font, text = "".toRunes, maxLen: int = text.len, color = NewVec4f(0.07, 0.07, 0.07, 1), verticalAlignment = VerticalAlignment.Center, horizontalAlignment = HorizontalAlignment.Center, maxWidth = 0'f32, transform = Unit4): Text = +proc InitText*(font: Font, text = "".toRunes, maxLen: int = text.len, color = NewVec4f(0.07, 0.07, 0.07, 1), verticalAlignment = VerticalAlignment.Center, horizontalAlignment = HorizontalAlignment.Center, maxWidth = 0'f32, transform = Unit4): Text = var positions = newSeq[Vec3f](int(maxLen * 4)) indices: seq[array[3, uint16]]
--- a/semicongine/vulkan/buffer.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/buffer.nim Tue Jun 04 22:08:48 2024 +0700 @@ -35,7 +35,7 @@ buffer.device.vk.vkGetBufferMemoryRequirements(buffer.vk, addr req) result.size = req.size result.alignment = req.alignment - let memorytypes = buffer.device.physicaldevice.vk.getMemoryProperties().types + let memorytypes = buffer.device.physicaldevice.vk.GetMemoryProperties().types for i in 0 ..< sizeof(req.memoryTypeBits) * 8: if ((req.memoryTypeBits shr i) and 1) == 1: result.memoryTypes.add memorytypes[i] @@ -45,7 +45,7 @@ assert buffer.memoryAllocated == false let requirements = buffer.requirements() - let memoryType = requirements.memoryTypes.selectBestMemoryType( + let memoryType = requirements.memoryTypes.SelectBestMemoryType( requireMappable = requireMappable, preferVRAM = preferVRAM, preferAutoFlush = preferAutoFlush @@ -59,13 +59,13 @@ size: buffer.size, usage: buffer.usage, memoryAllocated: true, - memory: buffer.device.allocate(requirements.size, memoryType) + memory: buffer.device.Allocate(requirements.size, memoryType) ) checkVkResult buffer.device.vk.vkBindBufferMemory(buffer.vk, buffer.memory.vk, VkDeviceSize(0)) # currently no support for extended structure and concurrent/shared use # (shardingMode = VK_SHARING_MODE_CONCURRENT not supported) -proc createBuffer*( +proc CreateBuffer*( device: Device, size: uint64, usage: openArray[VkBufferUsageFlagBits], @@ -98,7 +98,7 @@ result.allocateMemory(requireMappable = requireMappable, preferVRAM = preferVRAM, preferAutoFlush = preferAutoFlush) -proc copy*(src, dst: Buffer, queue: Queue, dstOffset = 0'u64) = +proc Copy*(src, dst: Buffer, queue: Queue, dstOffset = 0'u64) = assert src.device.vk.valid assert dst.device.vk.valid assert src.device == dst.device @@ -107,16 +107,16 @@ assert VK_BUFFER_USAGE_TRANSFER_DST_BIT in dst.usage var copyRegion = VkBufferCopy(size: VkDeviceSize(src.size), dstOffset: VkDeviceSize(dstOffset)) - withSingleUseCommandBuffer(src.device, queue, commandBuffer): + WithSingleUseCommandBuffer(src.device, queue, commandBuffer): commandBuffer.vkCmdCopyBuffer(src.vk, dst.vk, 1, addr(copyRegion)) -proc destroy*(buffer: var Buffer) = +proc Destroy*(buffer: var Buffer) = assert buffer.device.vk.valid assert buffer.vk.valid buffer.device.vk.vkDestroyBuffer(buffer.vk, nil) if buffer.memoryAllocated: assert buffer.memory.vk.valid - buffer.memory.free + buffer.memory.Free() buffer = Buffer( device: buffer.device, vk: buffer.vk, @@ -126,24 +126,24 @@ ) buffer.vk.reset -template canMap*(buffer: Buffer): bool = +template CanMap*(buffer: Buffer): bool = buffer.memory.canMap -proc setData*(dst: Buffer, queue: Queue, src: pointer, size: uint64, bufferOffset = 0'u64) = +proc SetData*(dst: Buffer, queue: Queue, src: pointer, size: uint64, bufferOffset = 0'u64) = assert bufferOffset + size <= dst.size - if dst.canMap: + if dst.CanMap: copyMem(cast[pointer](cast[uint](dst.memory.data) + bufferOffset), src, size) if dst.memory.needsFlushing: - dst.memory.flush() + dst.memory.Flush() else: # use staging buffer, slower but required if memory is not host visible - var stagingBuffer = dst.device.createBuffer(size, [VK_BUFFER_USAGE_TRANSFER_SRC_BIT], requireMappable = true, preferVRAM = false, preferAutoFlush = true) - setData(stagingBuffer, queue, src, size, 0) - stagingBuffer.copy(dst, queue, bufferOffset) - stagingBuffer.destroy() + var stagingBuffer = dst.device.CreateBuffer(size, [VK_BUFFER_USAGE_TRANSFER_SRC_BIT], requireMappable = true, preferVRAM = false, preferAutoFlush = true) + SetData(stagingBuffer, queue, src, size, 0) + stagingBuffer.Copy(dst, queue, bufferOffset) + stagingBuffer.Destroy() -proc setData*[T: seq](dst: Buffer, queue: Queue, src: ptr T, offset = 0'u64) = +proc SetData*[T: seq](dst: Buffer, queue: Queue, src: ptr T, offset = 0'u64) = dst.setData(queue, src, sizeof(get(genericParams(T), 0)) * src[].len, offset = offset) -proc setData*[T](dst: Buffer, queue: Queue, src: ptr T, offset = 0'u64) = +proc SetData*[T](dst: Buffer, queue: Queue, src: ptr T, offset = 0'u64) = dst.setData(queue, src, sizeof(T), offset = offset)
--- a/semicongine/vulkan/commandbuffer.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/commandbuffer.nim Tue Jun 04 22:08:48 2024 +0700 @@ -10,7 +10,7 @@ family*: QueueFamily buffers*: seq[VkCommandBuffer] -proc createCommandBufferPool*(device: Device, family: QueueFamily, nBuffers: int): CommandBufferPool = +proc CreateCommandBufferPool*(device: Device, family: QueueFamily, nBuffers: int): CommandBufferPool = assert device.vk.valid var createInfo = VkCommandPoolCreateInfo( sType: VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, @@ -30,7 +30,7 @@ result.buffers = newSeq[VkCommandBuffer](nBuffers) checkVkResult device.vk.vkAllocateCommandBuffers(addr allocInfo, result.buffers.ToCPointer) -proc pipelineBarrier*( +proc PipelineBarrier*( commandBuffer: VkCommandBuffer, srcStages: openArray[VkPipelineStageFlagBits], dstStages: openArray[VkPipelineStageFlagBits], @@ -53,14 +53,14 @@ ) -template withSingleUseCommandBuffer*(device: Device, queue: Queue, commandBuffer, body: untyped): untyped = +template WithSingleUseCommandBuffer*(device: Device, queue: Queue, commandBuffer, body: untyped): untyped = # TODO? This is super slow, because we call vkQueueWaitIdle block: assert device.vk.valid assert queue.vk.valid var - commandBufferPool = createCommandBufferPool(device, queue.family, 1) + commandBufferPool = CreateCommandBufferPool(device, queue.family, 1) commandBuffer = commandBufferPool.buffers[0] beginInfo = VkCommandBufferBeginInfo( sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, @@ -79,10 +79,10 @@ ) checkVkResult queue.vk.vkQueueSubmit(1, addr submitInfo, VkFence(0)) checkVkResult queue.vk.vkQueueWaitIdle() - commandBufferPool.destroy() + commandBufferPool.Destroy() -proc destroy*(commandpool: var CommandBufferPool) = +proc Destroy*(commandpool: var CommandBufferPool) = assert commandpool.device.vk.valid assert commandpool.vk.valid commandpool.device.vk.vkDestroyCommandPool(commandpool.vk, nil)
--- a/semicongine/vulkan/descriptor.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/descriptor.nim Tue Jun 04 22:08:48 2024 +0700 @@ -42,7 +42,7 @@ func vkType(descriptor: Descriptor): VkDescriptorType = DESCRIPTOR_TYPE_MAP[descriptor.thetype] -proc createDescriptorSetLayout*(device: Device, descriptors: seq[Descriptor]): DescriptorSetLayout = +proc CreateDescriptorSetLayout*(device: Device, descriptors: seq[Descriptor]): DescriptorSetLayout = assert device.vk.valid result.device = device @@ -64,13 +64,13 @@ ) checkVkResult vkCreateDescriptorSetLayout(device.vk, addr(layoutCreateInfo), nil, addr(result.vk)) -proc destroy*(descriptorSetLayout: var DescriptorSetLayout) = +proc Destroy*(descriptorSetLayout: var DescriptorSetLayout) = assert descriptorSetLayout.device.vk.valid assert descriptorSetLayout.vk.valid descriptorSetLayout.device.vk.vkDestroyDescriptorSetLayout(descriptorSetLayout.vk, nil) descriptorSetLayout.vk.reset -proc createDescriptorSetPool*(device: Device, counts: seq[(VkDescriptorType, uint32)], maxSets = 1000): DescriptorPool = +proc CreateDescriptorSetPool*(device: Device, counts: seq[(VkDescriptorType, uint32)], maxSets = 1000): DescriptorPool = assert device.vk.valid result.device = device @@ -88,18 +88,18 @@ ) checkVkResult vkCreateDescriptorPool(result.device.vk, addr(poolInfo), nil, addr(result.vk)) -proc reset*(pool: DescriptorPool) = +proc Reset*(pool: DescriptorPool) = assert pool.device.vk.valid assert pool.vk.valid checkVkResult vkResetDescriptorPool(pool.device.vk, pool.vk, VkDescriptorPoolResetFlags(0)) -proc destroy*(pool: var DescriptorPool) = +proc Destroy*(pool: var DescriptorPool) = assert pool.device.vk.valid assert pool.vk.valid pool.device.vk.vkDestroyDescriptorPool(pool.vk, nil) pool.vk.reset -proc allocateDescriptorSet*(pool: DescriptorPool, layout: DescriptorSetLayout, nframes: int): seq[DescriptorSet] = +proc AllocateDescriptorSet*(pool: DescriptorPool, layout: DescriptorSetLayout, nframes: int): seq[DescriptorSet] = assert pool.device.vk.valid assert pool.vk.valid assert layout.device.vk.valid @@ -120,7 +120,7 @@ for descriptorSet in descriptorSets: result.add DescriptorSet(vk: descriptorSet, layout: layout) -proc writeDescriptorSet*(descriptorSet: DescriptorSet, bindingBase = 0'u32) = +proc WriteDescriptorSet*(descriptorSet: DescriptorSet, bindingBase = 0'u32) = # assumes descriptors of the descriptorSet are arranged interleaved in buffer assert descriptorSet.layout.device.vk.valid assert descriptorSet.layout.vk.valid
--- a/semicongine/vulkan/device.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/device.nim Tue Jun 04 22:08:48 2024 +0700 @@ -21,7 +21,7 @@ proc `$`*(device: Device): string = "Device: vk=" & $device.vk -proc createDevice*( +proc CreateDevice*( instance: Instance, physicalDevice: PhysicalDevice, enabledExtensions: seq[string], @@ -88,21 +88,21 @@ for family in deviceQueues.keys: var queue: VkQueue vkGetDeviceQueue(result.vk, family.index, 0, addr queue) - result.queues[family] = Queue(vk: queue, family: family, presentation: family.canDoPresentation(physicalDevice.surface), graphics: family.canDoGraphics()) + result.queues[family] = Queue(vk: queue, family: family, presentation: family.CanDoPresentation(physicalDevice.surface), graphics: family.CanDoGraphics()) -func firstGraphicsQueue*(device: Device): Option[Queue] = +func FirstGraphicsQueue*(device: Device): Option[Queue] = assert device.vk.valid for family, queue in device.queues: if queue.graphics: return some(queue) -proc firstPresentationQueue*(device: Device): Option[Queue] = +proc FirstPresentationQueue*(device: Device): Option[Queue] = assert device.vk.valid for family, queue in device.queues: if queue.presentation: return some(queue) -proc destroy*(device: var Device) = +proc Destroy*(device: var Device) = assert device.vk.valid device.vk.vkDestroyDevice(nil) device.vk.reset()
--- a/semicongine/vulkan/drawable.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/drawable.nim Tue Jun 04 22:08:48 2024 +0700 @@ -24,7 +24,7 @@ else: &"Drawable({drawable.name}, elementCount: {drawable.elementCount}, instanceCount: {drawable.instanceCount}, bufferOffsets: {drawable.bufferOffsets})" -proc draw*(drawable: Drawable, commandBuffer: VkCommandBuffer, vertexBuffers: Table[MemoryPerformanceHint, Buffer], indexBuffer: Buffer, pipeline: VkPipeline) = +proc Draw*(drawable: Drawable, commandBuffer: VkCommandBuffer, vertexBuffers: Table[MemoryPerformanceHint, Buffer], indexBuffer: Buffer, pipeline: VkPipeline) = debug &"Draw {drawable} with pipeline {pipeline}" var buffers: seq[VkBuffer]
--- a/semicongine/vulkan/framebuffer.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/framebuffer.nim Tue Jun 04 22:08:48 2024 +0700 @@ -9,7 +9,7 @@ vk*: VkFramebuffer dimension*: Vec2u -proc createFramebuffer*(device: Device, renderpass: VkRenderPass, attachments: openArray[ImageView], dimension: Vec2u): Framebuffer = +proc CreateFramebuffer*(device: Device, renderpass: VkRenderPass, attachments: openArray[ImageView], dimension: Vec2u): Framebuffer = assert device.vk.valid assert renderpass.valid @@ -31,7 +31,7 @@ ) checkVkResult device.vk.vkCreateFramebuffer(addr(framebufferInfo), nil, addr(result.vk)) -proc destroy*(framebuffer: var Framebuffer) = +proc Destroy*(framebuffer: var Framebuffer) = assert framebuffer.device.vk.valid assert framebuffer.vk.valid framebuffer.device.vk.vkDestroyFramebuffer(framebuffer.vk, nil)
--- a/semicongine/vulkan/image.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/image.nim Tue Jun 04 22:08:48 2024 +0700 @@ -56,7 +56,7 @@ image.device.vk.vkGetImageMemoryRequirements(image.vk, addr req) result.size = req.size result.alignment = req.alignment - let memorytypes = image.device.physicaldevice.vk.getMemoryProperties().types + let memorytypes = image.device.physicaldevice.vk.GetMemoryProperties().types for i in 0 ..< sizeof(req.memoryTypeBits) * 8: if ((req.memoryTypeBits shr i) and 1) == 1: result.memoryTypes.add memorytypes[i] @@ -66,7 +66,7 @@ assert image.memoryAllocated == false let requirements = image.requirements() - let memoryType = requirements.memoryTypes.selectBestMemoryType( + let memoryType = requirements.memoryTypes.SelectBestMemoryType( requireMappable = requireMappable, preferVRAM = preferVRAM, preferAutoFlush = preferAutoFlush @@ -82,7 +82,7 @@ format: image.format, usage: image.usage, memoryAllocated: true, - memory: image.device.allocate(requirements.size, memoryType), + memory: image.device.Allocate(requirements.size, memoryType), ) checkVkResult image.device.vk.vkBindImageMemory(image.vk, image.memory.vk, VkDeviceSize(0)) @@ -118,10 +118,10 @@ else: raise newException(Exception, "Unsupported layout transition!") - withSingleUseCommandBuffer(image.device, queue, commandBuffer): - commandBuffer.pipelineBarrier([srcStage], [dstStage], imageBarriers = [barrier]) + WithSingleUseCommandBuffer(image.device, queue, commandBuffer): + commandBuffer.PipelineBarrier([srcStage], [dstStage], imageBarriers = [barrier]) -proc copy*(src: Buffer, dst: VulkanImage, queue: Queue) = +proc Copy*(src: Buffer, dst: VulkanImage, queue: Queue) = assert src.device.vk.valid assert dst.device.vk.valid assert src.device == dst.device @@ -141,7 +141,7 @@ imageOffset: VkOffset3D(x: 0, y: 0, z: 0), imageExtent: VkExtent3D(width: dst.width, height: dst.height, depth: 1) ) - withSingleUseCommandBuffer(src.device, queue, commandBuffer): + WithSingleUseCommandBuffer(src.device, queue, commandBuffer): commandBuffer.vkCmdCopyBufferToImage( src.vk, dst.vk, @@ -219,19 +219,19 @@ result.allocateMemory(requireMappable = false, preferVRAM = true, preferAutoFlush = false) result.transitionImageLayout(queue, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) - var stagingBuffer = device.createBuffer(size = size, usage = [VK_BUFFER_USAGE_TRANSFER_SRC_BIT], requireMappable = true, preferVRAM = false, preferAutoFlush = true) - stagingBuffer.setData(queue, src = data, size = size) - stagingBuffer.copy(result, queue) + var stagingBuffer = device.CreateBuffer(size = size, usage = [VK_BUFFER_USAGE_TRANSFER_SRC_BIT], requireMappable = true, preferVRAM = false, preferAutoFlush = true) + stagingBuffer.SetData(queue, src = data, size = size) + stagingBuffer.Copy(result, queue) result.transitionImageLayout(queue, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) - stagingBuffer.destroy() + stagingBuffer.Destroy() -proc destroy*(image: var VulkanImage) = +proc Destroy*(image: var VulkanImage) = assert image.device.vk.valid assert image.vk.valid image.device.vk.vkDestroyImage(image.vk, nil) if image.memoryAllocated: assert image.memory.vk.valid - image.memory.free + image.memory.Free() image = VulkanImage( device: image.device, vk: image.vk, @@ -244,7 +244,7 @@ ) image.vk.reset -proc createSampler*(device: Device, sampler: Sampler): VulkanSampler = +proc CreateSampler*(device: Device, sampler: Sampler): VulkanSampler = assert device.vk.valid var samplerInfo = VkSamplerCreateInfo( sType: VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, @@ -267,13 +267,13 @@ result.device = device checkVkResult device.vk.vkCreateSampler(addr samplerInfo, nil, addr result.vk) -proc destroy*(sampler: var VulkanSampler) = +proc Destroy*(sampler: var VulkanSampler) = assert sampler.device.vk.valid assert sampler.vk.valid sampler.device.vk.vkDestroySampler(sampler.vk, nil) sampler.vk.reset -proc createImageView*( +proc CreateImageView*( image: VulkanImage, imageviewtype = VK_IMAGE_VIEW_TYPE_2D, baseMipLevel = 0'u32, @@ -306,7 +306,7 @@ result.image = image checkVkResult image.device.vk.vkCreateImageView(addr(createInfo), nil, addr(result.vk)) -proc destroy*(imageview: var ImageView) = +proc Destroy*(imageview: var ImageView) = assert imageview.image.device.vk.valid assert imageview.vk.valid imageview.image.device.vk.vkDestroyImageView(imageview.vk, nil) @@ -316,16 +316,16 @@ &"VulkanTexture({texture.image.width}x{texture.image.height})" -proc uploadTexture*(device: Device, queue: Queue, texture: Texture): VulkanTexture = +proc UploadTexture*(device: Device, queue: Queue, texture: Texture): VulkanTexture = assert device.vk.valid if texture.isGrayscale: result.image = createImage(device = device, queue = queue, width = texture.grayImage.width, height = texture.grayImage.height, depth = 1, image = texture.grayImage) else: result.image = createImage(device = device, queue = queue, width = texture.colorImage.width, height = texture.colorImage.height, depth = 4, image = texture.colorImage) - result.imageView = result.image.createImageView() - result.sampler = result.image.device.createSampler(texture.sampler) + result.imageView = result.image.CreateImageView() + result.sampler = result.image.device.CreateSampler(texture.sampler) -proc destroy*(texture: var VulkanTexture) = - texture.image.destroy() - texture.imageView.destroy() - texture.sampler.destroy() +proc Destroy*(texture: var VulkanTexture) = + texture.image.Destroy() + texture.imageView.Destroy() + texture.sampler.Destroy()
--- a/semicongine/vulkan/instance.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/instance.nim Tue Jun 04 22:08:48 2024 +0700 @@ -24,7 +24,7 @@ userData: pointer ): VkBool32 {.cdecl.} -proc getInstanceExtensions*(): seq[string] = +proc GetInstanceExtensions*(): seq[string] = var extensionCount: uint32 checkVkResult vkEnumerateInstanceExtensionProperties(nil, addr(extensionCount), nil) if extensionCount > 0: @@ -33,7 +33,7 @@ for extension in extensions: result.add(CleanString(extension.extensionName)) -proc getLayers*(): seq[string] = +proc GetLayers*(): seq[string] = var n_layers: uint32 checkVkResult vkEnumerateInstanceLayerProperties(addr(n_layers), nil) if n_layers > 0: @@ -42,7 +42,7 @@ for layer in layers: result.add(CleanString(layer.layerName)) -proc createInstance*( +proc CreateInstance*( window: NativeWindow, vulkanVersion: uint32, instanceExtensions: seq[string], @@ -53,10 +53,10 @@ let requiredExtensions = REQUIRED_PLATFORM_EXTENSIONS & @["VK_KHR_surface"] & instanceExtensions for i in requiredExtensions: - assert i in getInstanceExtensions(), $i + assert i in GetInstanceExtensions(), $i var availableLayers: seq[string] for i in layers: - if i in getLayers(): + if i in GetLayers(): availableLayers.add i debug "Enabled layers: " & $availableLayers var @@ -82,9 +82,9 @@ deallocCStringArray(instanceExtensionsC) for extension in requiredExtensions: result.vk.loadExtension($extension) - result.surface = result.vk.createNativeSurface(window) + result.surface = result.vk.CreateNativeSurface(window) -proc destroy*(instance: var Instance) = +proc Destroy*(instance: var Instance) = assert instance.vk.valid assert instance.surface.valid # needs to happen after window is trashed as the driver might have a hook registered for the window destruction @@ -113,7 +113,7 @@ raise newException(Exception, errorMsg) return false -proc createDebugMessenger*( +proc CreateDebugMessenger*( instance: Instance, severityLevels: openArray[VkDebugUtilsMessageSeverityFlagBitsEXT] = @[], types: openArray[VkDebugUtilsMessageTypeFlagBitsEXT] = @[], @@ -136,7 +136,7 @@ ) checkVkResult instance.vk.vkCreateDebugUtilsMessengerEXT(addr(createInfo), nil, addr(result.messenger)) -proc destroy*(debugger: var Debugger) = +proc Destroy*(debugger: var Debugger) = assert debugger.messenger.valid assert debugger.instance.vk.valid debugger.instance.vk.vkDestroyDebugUtilsMessengerEXT(debugger.messenger, nil)
--- a/semicongine/vulkan/memory.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/memory.nim Tue Jun 04 22:08:48 2024 +0700 @@ -32,7 +32,7 @@ func `$`*(memoryType: MemoryType): string = &"Memorytype {memoryType.flags} (heap size: {memoryType.heap.size}, heap flags: {memoryType.heap.flags})" -proc selectBestMemoryType*(types: seq[MemoryType], requireMappable: bool, preferVRAM: bool, preferAutoFlush: bool): MemoryType = +proc SelectBestMemoryType*(types: seq[MemoryType], requireMappable: bool, preferVRAM: bool, preferAutoFlush: bool): MemoryType = # todo: we assume there is always at least one memory type that is mappable assert types.len > 0 var highestRating = 0'f @@ -49,7 +49,7 @@ highestRating = rating result = t -proc getMemoryProperties*(physicalDevice: VkPhysicalDevice): PhyscialDeviceMemoryProperties = +proc GetMemoryProperties*(physicalDevice: VkPhysicalDevice): PhyscialDeviceMemoryProperties = var physicalProperties: VkPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties(physicalDevice, addr physicalProperties) for i in 0 ..< physicalProperties.memoryHeapCount: @@ -65,7 +65,7 @@ index: i, ) -proc allocate*(device: Device, size: uint64, memoryType: MemoryType): DeviceMemory = +proc Allocate*(device: Device, size: uint64, memoryType: MemoryType): DeviceMemory = assert device.vk.valid assert size > 0 result = DeviceMemory( @@ -99,7 +99,7 @@ ) # flush host -> device -proc flush*(memory: DeviceMemory, offset = 0'u64, size = 0'u64) = +proc Flush*(memory: DeviceMemory, offset = 0'u64, size = 0'u64) = assert memory.device.vk.valid assert memory.vk.valid assert memory.needsFlushing @@ -116,7 +116,7 @@ checkVkResult memory.device.vk.vkFlushMappedMemoryRanges(memoryRangeCount = 1, pMemoryRanges = addr(flushrange)) # flush device -> host -proc invalidate*(memory: DeviceMemory, offset = 0'u64, size = 0'u64) = +proc Invalidate*(memory: DeviceMemory, offset = 0'u64, size = 0'u64) = assert memory.device.vk.valid assert memory.vk.valid assert memory.needsFlushing @@ -132,7 +132,7 @@ ) checkVkResult memory.device.vk.vkInvalidateMappedMemoryRanges(memoryRangeCount = 1, pMemoryRanges = addr(flushrange)) -proc free*(memory: var DeviceMemory) = +proc Free*(memory: var DeviceMemory) = assert memory.device.vk.valid assert memory.vk.valid
--- a/semicongine/vulkan/physicaldevice.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/physicaldevice.nim Tue Jun 04 22:08:48 2024 +0700 @@ -22,7 +22,7 @@ func `$`*(device: PhysicalDevice): string = "Physical device: vk=" & $device.vk & ", name=" & $device.name & ", devicetype=" & $device.devicetype -proc getPhysicalDevices*(instance: Instance): seq[PhysicalDevice] = +proc GetPhysicalDevices*(instance: Instance): seq[PhysicalDevice] = assert instance.vk.valid assert instance.surface.valid var nDevices: uint32 @@ -38,7 +38,7 @@ device.devicetype = device.properties.deviceType result.add device -proc getExtensions*(device: PhysicalDevice): seq[string] = +proc GetExtensions*(device: PhysicalDevice): seq[string] = assert device.vk.valid var extensionCount: uint32 checkVkResult vkEnumerateDeviceExtensionProperties(device.vk, nil, addr(extensionCount), nil) @@ -48,12 +48,12 @@ for extension in extensions: result.add(CleanString(extension.extensionName)) -proc getSurfaceCapabilities*(device: PhysicalDevice): VkSurfaceCapabilitiesKHR = +proc GetSurfaceCapabilities*(device: PhysicalDevice): VkSurfaceCapabilitiesKHR = assert device.vk.valid assert device.surface.valid checkVkResult device.vk.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device.surface, addr(result)) -proc getSurfaceFormats*(device: PhysicalDevice): seq[VkSurfaceFormatKHR] = +proc GetSurfaceFormats*(device: PhysicalDevice): seq[VkSurfaceFormatKHR] = assert device.vk.valid assert device.surface.valid var n_formats: uint32 @@ -61,7 +61,7 @@ result = newSeq[VkSurfaceFormatKHR](n_formats) checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device.vk, device.surface, addr(n_formats), result.ToCPointer) -func filterSurfaceFormat*( +func FilterSurfaceFormat*( formats: seq[VkSurfaceFormatKHR], imageFormat = VK_FORMAT_B8G8R8A8_SRGB, colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR @@ -70,12 +70,12 @@ if format.format == imageFormat and format.colorSpace == colorSpace: return format -proc filterSurfaceFormat*(device: PhysicalDevice): VkSurfaceFormatKHR = +proc FilterSurfaceFormat*(device: PhysicalDevice): VkSurfaceFormatKHR = assert device.vk.valid assert device.surface.valid - device.getSurfaceFormats().filterSurfaceFormat() + device.GetSurfaceFormats().FilterSurfaceFormat() -proc getSurfacePresentModes*(device: PhysicalDevice): seq[VkPresentModeKHR] = +proc GetSurfacePresentModes*(device: PhysicalDevice): seq[VkPresentModeKHR] = assert device.vk.valid assert device.surface.valid var n_modes: uint32 @@ -83,7 +83,7 @@ result = newSeq[VkPresentModeKHR](n_modes) checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device.vk, device.surface, addr(n_modes), result.ToCPointer) -proc getQueueFamilies*(device: PhysicalDevice): seq[QueueFamily] = +proc GetQueueFamilies*(device: PhysicalDevice): seq[QueueFamily] = assert device.vk.valid var nQueuefamilies: uint32 vkGetPhysicalDeviceQueueFamilyProperties(device.vk, addr nQueuefamilies, nil) @@ -97,27 +97,27 @@ flags: queuFamilies[i].queueFlags.toEnums, ) -proc canDoGraphics*(family: QueueFamily): bool = +proc CanDoGraphics*(family: QueueFamily): bool = VK_QUEUE_GRAPHICS_BIT in family.flags -proc canDoPresentation*(family: QueueFamily, surface: VkSurfaceKHR): bool = +proc CanDoPresentation*(family: QueueFamily, surface: VkSurfaceKHR): bool = assert surface.valid var presentation = VkBool32(false) checkVkResult vkGetPhysicalDeviceSurfaceSupportKHR(family.device.vk, family.index, surface, addr presentation) return bool(presentation) -proc canDoTransfer*(family: QueueFamily): bool = +proc CanDoTransfer*(family: QueueFamily): bool = VK_QUEUE_TRANSFER_BIT in family.flags -proc filterForGraphicsPresentationQueues*(device: PhysicalDevice): seq[QueueFamily] = +proc FilterForGraphicsPresentationQueues*(device: PhysicalDevice): seq[QueueFamily] = var canDoGraphics = false var canDoPresentation = false var queues: Table[uint32, QueueFamily] - for family in device.getQueueFamilies(): - if family.canDoGraphics: + for family in device.GetQueueFamilies(): + if family.CanDoGraphics: queues[family.index] = family canDoGraphics = true - if family.canDoPresentation(device.surface): + if family.CanDoPresentation(device.surface): queues[family.index] = family canDoPresentation = true if canDoGraphics and canDoPresentation: @@ -125,21 +125,21 @@ proc filterGraphics(families: seq[QueueFamily]): seq[QueueFamily] = for family in families: - if family.canDoGraphics: + if family.CanDoGraphics: result.add family proc filterPresentation(families: seq[QueueFamily], surface: VkSurfaceKHR): seq[QueueFamily] = assert surface.valid for family in families: - if family.canDoPresentation(surface): + if family.CanDoPresentation(surface): result.add family -proc rateGraphics*(device: PhysicalDevice): float = +proc rateGraphics(device: PhysicalDevice): float = assert device.vk.valid assert device.surface.valid - if device.getQueueFamilies().filterGraphics().filterPresentation(device.surface).len == 0: + if device.GetQueueFamilies().filterGraphics().filterPresentation(device.surface).len == 0: return -1 - if not ("VK_KHR_swapchain" in device.getExtensions()): + if not ("VK_KHR_swapchain" in device.GetExtensions()): return -1 const deviceTypeMap = [ VK_PHYSICAL_DEVICE_TYPE_OTHER, @@ -152,7 +152,7 @@ if device.devicetype == devicetype: result = float(i) -proc filterBestGraphics*(devices: seq[PhysicalDevice]): PhysicalDevice = +proc FilterBestGraphics*(devices: seq[PhysicalDevice]): PhysicalDevice = var bestVal = -1'f for device in devices: assert device.vk.valid
--- a/semicongine/vulkan/pipeline.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/pipeline.nim Tue Jun 04 22:08:48 2024 +0700 @@ -18,20 +18,20 @@ shaderModules*: (ShaderModule, ShaderModule) descriptorSetLayout*: DescriptorSetLayout -func inputs*(pipeline: ShaderPipeline): seq[ShaderAttribute] = +func Inputs*(pipeline: ShaderPipeline): seq[ShaderAttribute] = pipeline.shaderConfiguration.inputs -func uniforms*(pipeline: ShaderPipeline): seq[ShaderAttribute] = +func Uniforms*(pipeline: ShaderPipeline): seq[ShaderAttribute] = pipeline.shaderConfiguration.uniforms -func samplers*(pipeline: ShaderPipeline): seq[ShaderAttribute] = +func Samplers*(pipeline: ShaderPipeline): seq[ShaderAttribute] = pipeline.shaderConfiguration.samplers -proc setupDescriptors*(pipeline: ShaderPipeline, descriptorPool: DescriptorPool, buffers: seq[Buffer], textures: var Table[string, seq[VulkanTexture]], inFlightFrames: int, emptyTexture: VulkanTexture): seq[DescriptorSet] = +proc SetupDescriptors*(pipeline: ShaderPipeline, descriptorPool: DescriptorPool, buffers: seq[Buffer], textures: var Table[string, seq[VulkanTexture]], inFlightFrames: int, emptyTexture: VulkanTexture): seq[DescriptorSet] = assert pipeline.vk.valid assert buffers.len == 0 or buffers.len == inFlightFrames # need to guard against this in case we have no uniforms, then we also create no buffers - result = descriptorPool.allocateDescriptorSet(pipeline.descriptorSetLayout, inFlightFrames) + result = descriptorPool.AllocateDescriptorSet(pipeline.descriptorSetLayout, inFlightFrames) for i in 0 ..< inFlightFrames: var offset = 0'u64 @@ -55,12 +55,12 @@ descriptor.imageviews.add emptyTexture.imageView descriptor.samplers.add emptyTexture.sampler -proc createPipeline*(device: Device, renderPass: VkRenderPass, shaderConfiguration: ShaderConfiguration, inFlightFrames: int, subpass = 0'u32, backFaceCulling = true): ShaderPipeline = +proc CreatePipeline*(device: Device, renderPass: VkRenderPass, shaderConfiguration: ShaderConfiguration, inFlightFrames: int, subpass = 0'u32, backFaceCulling = true): ShaderPipeline = assert renderPass.valid assert device.vk.valid result.device = device - result.shaderModules = device.createShaderModules(shaderConfiguration) + result.shaderModules = device.CreateShaderModules(shaderConfiguration) result.shaderConfiguration = shaderConfiguration var descriptors: seq[Descriptor] @@ -79,7 +79,7 @@ count: (if sampler.arrayCount == 0: 1 else: sampler.arrayCount), stages: @[VK_SHADER_STAGE_VERTEX_BIT, VK_SHADER_STAGE_FRAGMENT_BIT], ) - result.descriptorSetLayout = device.createDescriptorSetLayout(descriptors) + result.descriptorSetLayout = device.CreateDescriptorSetLayout(descriptors) # TODO: Push constants # var pushConstant = VkPushConstantRange( @@ -101,7 +101,7 @@ var bindings: seq[VkVertexInputBindingDescription] attributes: seq[VkVertexInputAttributeDescription] - vertexInputInfo = result.shaderConfiguration.getVertexInputInfo(bindings, attributes) + vertexInputInfo = result.shaderConfiguration.GetVertexInputInfo(bindings, attributes) inputAssembly = VkPipelineInputAssemblyStateCreateInfo( sType: VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, topology: VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, @@ -156,7 +156,7 @@ dynamicStateCount: uint32(dynamicStates.len), pDynamicStates: dynamicStates.ToCPointer, ) - stages = @[result.shaderModules[0].getPipelineInfo(), result.shaderModules[1].getPipelineInfo()] + stages = @[result.shaderModules[0].GetPipelineInfo(), result.shaderModules[1].GetPipelineInfo()] createInfo = VkGraphicsPipelineCreateInfo( sType: VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, stageCount: uint32(stages.len), @@ -184,18 +184,18 @@ addr(result.vk) ) - discard result.uniforms # just for assertion + discard result.Uniforms # just for assertion -proc destroy*(pipeline: var ShaderPipeline) = +proc Destroy*(pipeline: var ShaderPipeline) = assert pipeline.device.vk.valid assert pipeline.vk.valid assert pipeline.layout.valid assert pipeline.descriptorSetLayout.vk.valid - pipeline.shaderModules[0].destroy() - pipeline.shaderModules[1].destroy() - pipeline.descriptorSetLayout.destroy() + pipeline.shaderModules[0].Destroy() + pipeline.shaderModules[1].Destroy() + pipeline.descriptorSetLayout.Destroy() pipeline.device.vk.vkDestroyPipelineLayout(pipeline.layout, nil) pipeline.device.vk.vkDestroyPipeline(pipeline.vk, nil) pipeline.descriptorSetLayout.reset()
--- a/semicongine/vulkan/renderpass.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/renderpass.nim Tue Jun 04 22:08:48 2024 +0700 @@ -13,7 +13,7 @@ shaderPipelines*: seq[(MaterialType, ShaderPipeline)] clearColor*: Vec4f -proc createRenderPass*( +proc CreateRenderPass*( device: Device, shaders: openArray[(MaterialType, ShaderConfiguration)], clearColor = Vec4f([0.8'f32, 0.8'f32, 0.8'f32, 1'f32]), @@ -24,11 +24,11 @@ # some asserts for (materialtype, shaderconfig) in shaders: - shaderconfig.assertCanRender(materialtype) + shaderconfig.AssertCanRender(materialtype) var attachments = @[VkAttachmentDescription( - format: device.physicalDevice.getSurfaceFormats().filterSurfaceFormat().format, + format: device.physicalDevice.GetSurfaceFormats().FilterSurfaceFormat().format, samples: VK_SAMPLE_COUNT_1_BIT, loadOp: VK_ATTACHMENT_LOAD_OP_CLEAR, storeOp: VK_ATTACHMENT_STORE_OP_STORE, @@ -84,9 +84,9 @@ for (_, shaderconfig) in shaders: assert shaderconfig.outputs.len == 1 for (materialtype, shaderconfig) in shaders: - result.shaderPipelines.add (materialtype, device.createPipeline(result.vk, shaderconfig, inFlightFrames, 0, backFaceCulling = backFaceCulling)) + result.shaderPipelines.add (materialtype, device.CreatePipeline(result.vk, shaderconfig, inFlightFrames, 0, backFaceCulling = backFaceCulling)) -proc beginRenderCommands*(commandBuffer: VkCommandBuffer, renderpass: RenderPass, framebuffer: Framebuffer, oneTimeSubmit: bool) = +proc BeginRenderCommands*(commandBuffer: VkCommandBuffer, renderpass: RenderPass, framebuffer: Framebuffer, oneTimeSubmit: bool) = assert commandBuffer.valid assert renderpass.vk.valid assert framebuffer.vk.valid @@ -130,15 +130,15 @@ commandBuffer.vkCmdSetViewport(firstViewport = 0, viewportCount = 1, addr(viewport)) commandBuffer.vkCmdSetScissor(firstScissor = 0, scissorCount = 1, addr(scissor)) -proc endRenderCommands*(commandBuffer: VkCommandBuffer) = +proc EndRenderCommands*(commandBuffer: VkCommandBuffer) = commandBuffer.vkCmdEndRenderPass() checkVkResult commandBuffer.vkEndCommandBuffer() -proc destroy*(renderPass: var RenderPass) = +proc Destroy*(renderPass: var RenderPass) = assert renderPass.device.vk.valid assert renderPass.vk.valid renderPass.device.vk.vkDestroyRenderPass(renderPass.vk, nil) renderPass.vk.reset for _, pipeline in renderPass.shaderPipelines.mitems: - pipeline.destroy() + pipeline.Destroy()
--- a/semicongine/vulkan/shader.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/shader.nim Tue Jun 04 22:08:48 2024 +0700 @@ -87,7 +87,7 @@ ) i += 4 -proc compileGlslCode*( +proc compileGlslCode( stage: VkShaderStageFlagBits, inputs: openArray[ShaderAttribute] = [], uniforms: openArray[ShaderAttribute] = [], @@ -108,7 +108,7 @@ @[&"}}"] compileGlslToSPIRV(stage, code.join("\n"), entrypoint) -proc createShaderConfiguration*( +proc CreateShaderConfiguration*( name: string, inputs: openArray[ShaderAttribute] = [], intermediates: openArray[ShaderAttribute] = [], @@ -147,7 +147,7 @@ ) -proc createShaderModules*( +proc CreateShaderModules*( device: Device, shaderConfiguration: ShaderConfiguration, ): (ShaderModule, ShaderModule) = @@ -175,7 +175,7 @@ ) checkVkResult vkCreateShaderModule(device.vk, addr(createInfoFragment), nil, addr(result[1].vk)) -proc getVertexInputInfo*( +proc GetVertexInputInfo*( shaderConfiguration: ShaderConfiguration, bindings: var seq[VkVertexInputBindingDescription], attributes: var seq[VkVertexInputAttributeDescription], @@ -210,7 +210,7 @@ ) -proc getPipelineInfo*(shader: ShaderModule): VkPipelineShaderStageCreateInfo = +proc GetPipelineInfo*(shader: ShaderModule): VkPipelineShaderStageCreateInfo = VkPipelineShaderStageCreateInfo( sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, stage: shader.stage, @@ -218,7 +218,7 @@ pName: cstring(shader.configuration.entrypoint), ) -proc destroy*(shader: var ShaderModule) = +proc Destroy*(shader: var ShaderModule) = assert shader.device.vk.valid assert shader.vk.valid shader.device.vk.vkDestroyShaderModule(shader.vk, nil)
--- a/semicongine/vulkan/swapchain.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/swapchain.nim Tue Jun 04 22:08:48 2024 +0700 @@ -30,7 +30,7 @@ vSync: bool -proc createSwapchain*( +proc CreateSwapchain*( device: Device, renderPass: VkRenderPass, surfaceFormat: VkSurfaceFormatKHR, @@ -44,7 +44,7 @@ assert renderPass.valid assert inFlightFrames > 0 - var capabilities = device.physicalDevice.getSurfaceCapabilities() + var capabilities = device.physicalDevice.GetSurfaceCapabilities() if capabilities.currentExtent.width == 0 or capabilities.currentExtent.height == 0: return none(Swapchain) @@ -54,7 +54,7 @@ minFramebufferCount = max(minFramebufferCount, capabilities.minImageCount) if capabilities.maxImageCount != 0: minFramebufferCount = min(minFramebufferCount, capabilities.maxImageCount) - let hasTripleBuffering = VK_PRESENT_MODE_MAILBOX_KHR in device.physicalDevice.getSurfacePresentModes() + let hasTripleBuffering = VK_PRESENT_MODE_MAILBOX_KHR in device.physicalDevice.GetSurfacePresentModes() var createInfo = VkSwapchainCreateInfoKHR( sType: VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, surface: device.physicalDevice.surface, @@ -87,30 +87,30 @@ var framebuffers = newSeq[VkImage](swapchain.nFramebuffers) checkVkResult device.vk.vkGetSwapchainImagesKHR(swapchain.vk, addr swapchain.nFramebuffers, framebuffers.ToCPointer) for framebuffer in framebuffers: - let framebufferView = VulkanImage(vk: framebuffer, format: surfaceFormat.format, device: device).createImageView() + let framebufferView = VulkanImage(vk: framebuffer, format: surfaceFormat.format, device: device).CreateImageView() swapchain.framebufferViews.add framebufferView - swapchain.framebuffers.add device.createFramebuffer(renderPass, [framebufferView], swapchain.dimension) + swapchain.framebuffers.add device.CreateFramebuffer(renderPass, [framebufferView], swapchain.dimension) for i in 0 ..< swapchain.inFlightFrames: - swapchain.queueFinishedFence.add device.createFence() - swapchain.imageAvailableSemaphore.add device.createSemaphore() - swapchain.renderFinishedSemaphore.add device.createSemaphore() + swapchain.queueFinishedFence.add device.CreateFence() + swapchain.imageAvailableSemaphore.add device.CreateSemaphore() + swapchain.renderFinishedSemaphore.add device.CreateSemaphore() debug &"Created swapchain with: {swapchain.nFramebuffers} framebuffers, {inFlightFrames} in-flight frames, {swapchain.dimension.x}x{swapchain.dimension.y}" - assert device.firstPresentationQueue().isSome, "No present queue found" - swapchain.presentQueue = device.firstPresentationQueue().get + assert device.FirstPresentationQueue().isSome, "No present queue found" + swapchain.presentQueue = device.FirstPresentationQueue().get result = some(swapchain) else: result = none(Swapchain) -proc currentFramebuffer*(swapchain: Swapchain): Framebuffer = +proc CurrentFramebuffer*(swapchain: Swapchain): Framebuffer = assert swapchain.device.vk.valid assert swapchain.vk.valid swapchain.framebuffers[swapchain.currentFramebufferIndex] -proc acquireNextFrame*(swapchain: var Swapchain): bool = +proc AcquireNextFrame*(swapchain: var Swapchain): bool = assert swapchain.device.vk.valid assert swapchain.vk.valid - swapchain.queueFinishedFence[swapchain.currentInFlight].await() + swapchain.queueFinishedFence[swapchain.currentInFlight].Await() let nextImageResult = swapchain.device.vk.vkAcquireNextImageKHR( swapchain.vk, @@ -126,7 +126,7 @@ else: return false -proc swap*(swapchain: var Swapchain, queue: Queue, commandBuffer: VkCommandBuffer): bool = +proc Swap*(swapchain: var Swapchain, queue: Queue, commandBuffer: VkCommandBuffer): bool = assert swapchain.device.vk.valid assert swapchain.vk.valid assert queue.vk.valid @@ -166,30 +166,30 @@ return true -proc destroy*(swapchain: var Swapchain) = +proc Destroy*(swapchain: var Swapchain) = assert swapchain.vk.valid for imageview in swapchain.framebufferViews.mitems: assert imageview.vk.valid - imageview.destroy() + imageview.Destroy() for framebuffer in swapchain.framebuffers.mitems: assert framebuffer.vk.valid - framebuffer.destroy() + framebuffer.Destroy() for i in 0 ..< swapchain.inFlightFrames: assert swapchain.queueFinishedFence[i].vk.valid assert swapchain.imageAvailableSemaphore[i].vk.valid assert swapchain.renderFinishedSemaphore[i].vk.valid - swapchain.queueFinishedFence[i].destroy() - swapchain.imageAvailableSemaphore[i].destroy() - swapchain.renderFinishedSemaphore[i].destroy() + swapchain.queueFinishedFence[i].Destroy() + swapchain.imageAvailableSemaphore[i].Destroy() + swapchain.renderFinishedSemaphore[i].Destroy() swapchain.device.vk.vkDestroySwapchainKHR(swapchain.vk, nil) swapchain.vk.reset() -proc recreate*(swapchain: var Swapchain): Option[Swapchain] = +proc Recreate*(swapchain: var Swapchain): Option[Swapchain] = assert swapchain.vk.valid assert swapchain.device.vk.valid - result = createSwapchain( + result = CreateSwapchain( device = swapchain.device, renderPass = swapchain.renderPass, surfaceFormat = swapchain.surfaceFormat,
--- a/semicongine/vulkan/syncing.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/semicongine/vulkan/syncing.nim Tue Jun 04 22:08:48 2024 +0700 @@ -10,13 +10,13 @@ device: Device awaitAction: proc() = nil -proc createSemaphore*(device: Device): Semaphore = +proc CreateSemaphore*(device: Device): Semaphore = assert device.vk.valid var semaphoreInfo = VkSemaphoreCreateInfo(sType: VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO) result.device = device checkVkResult device.vk.vkCreateSemaphore(addr(semaphoreInfo), nil, addr(result.vk)) -proc createFence*(device: Device, awaitAction: proc() = nil): Fence = +proc CreateFence*(device: Device, awaitAction: proc() = nil): Fence = assert device.vk.valid var fenceInfo = VkFenceCreateInfo( sType: VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, @@ -26,25 +26,25 @@ result.awaitAction = awaitAction checkVkResult device.vk.vkCreateFence(addr(fenceInfo), nil, addr(result.vk)) -proc await*(fence: var Fence) = +proc Await*(fence: var Fence) = assert fence.device.vk.valid assert fence.vk.valid checkVkResult vkWaitForFences(fence.device.vk, 1, addr fence.vk, false, high(uint64)) if fence.awaitAction != nil: fence.awaitAction() -proc reset*(fence: var Fence) = +proc Reset*(fence: var Fence) = assert fence.device.vk.valid assert fence.vk.valid checkVkResult fence.device.vk.vkResetFences(1, addr fence.vk) -proc destroy*(semaphore: var Semaphore) = +proc Destroy*(semaphore: var Semaphore) = assert semaphore.device.vk.valid assert semaphore.vk.valid semaphore.device.vk.vkDestroySemaphore(semaphore.vk, nil) semaphore.vk.reset -proc destroy*(fence: var Fence) = +proc Destroy*(fence: var Fence) = assert fence.device.vk.valid assert fence.vk.valid fence.device.vk.vkDestroyFence(fence.vk, nil)
--- a/tests/test_collision.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/tests/test_collision.nim Tue Jun 04 22:08:48 2024 +0700 @@ -28,10 +28,10 @@ fragmentCode = """fragcolor = colorout;""", ) - var engine = initEngine("Test collisions") + var engine = InitEngine("Test collisions") - engine.initRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}) - engine.loadScene(scene) + engine.InitRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}) + engine.LoadScene(scene) while engine.UpdateInputs() and not KeyIsDown(Escape): if WindowWasResized(): @@ -51,8 +51,8 @@ let hitbox = Collider(theType: Box, transform: scene.meshes[0].transform * Translate(-0.5, -0.5)) let hitsphere = Collider(theType: Sphere, transform: scene.meshes[2].transform, radius: 0.5) echo intersects(hitbox, hitsphere) - engine.renderScene(scene) - engine.destroy() + engine.RenderScene(scene) + engine.Destroy() when isMainModule:
--- a/tests/test_font.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/tests/test_font.nim Tue Jun 04 22:08:48 2024 +0700 @@ -6,8 +6,8 @@ proc main() = # setup engine - var engine = initEngine("Test fonts") - engine.initRenderer([]) + var engine = InitEngine("Test fonts") + engine.InitRenderer([]) # build scene var scene = Scene(name: "main") @@ -27,7 +27,7 @@ scene.add origin scene.add main_text scene.add help_text - engine.loadScene(scene) + engine.LoadScene(scene) mixer[].LoadSound("key", "key.ogg") mixer[].SetLevel(0.5) @@ -71,8 +71,8 @@ main_text.refresh() main_text.text = main_text.text[0 ..< ^1] help_text.refresh() - engine.renderScene(scene) - engine.destroy() + engine.RenderScene(scene) + engine.Destroy() when isMainModule:
--- a/tests/test_materials.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/tests/test_materials.nim Tue Jun 04 22:08:48 2024 +0700 @@ -37,7 +37,7 @@ var scene = Scene(name: "main", meshes: @[flag]) scene.addShaderGlobalArray("test2", @[NewVec4f(), NewVec4f()]) - var engine = initEngine("Test materials") + var engine = InitEngine("Test materials") const shaderConfiguration1 = createShaderConfiguration( @@ -63,16 +63,16 @@ color = texture(tex1, uvout) * (1 - d) + texture(tex2, uvout) * d; """, ) - engine.initRenderer({ + engine.InitRenderer({ doubleTextureMaterial: shaderConfiguration1, }) - engine.loadScene(scene) + engine.LoadScene(scene) var t = cpuTime() while engine.UpdateInputs() and not KeyIsDown(Escape): var d = float32(cpuTime() - t) setShaderGlobalArray(scene, "test2", @[NewVec4f(d), NewVec4f(d * 2)]) - engine.renderScene(scene) - engine.destroy() + engine.RenderScene(scene) + engine.Destroy() when isMainModule:
--- a/tests/test_mesh.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/tests/test_mesh.nim Tue Jun 04 22:08:48 2024 +0700 @@ -16,7 +16,7 @@ Scene(name: "Donut", meshes: loadMeshes("donut.glb", MeshMaterial)[0].toSeq), ] - var engine = initEngine("Test meshes") + var engine = InitEngine("Test meshes") const shaderConfiguration = createShaderConfiguration( name = "default shader", @@ -46,12 +46,12 @@ """, fragmentCode = "color = texture(baseTexture[materialIndexOut], colorTexCoord) * vertexColor;" ) - engine.initRenderer({MeshMaterial: shaderConfiguration}) + engine.InitRenderer({MeshMaterial: shaderConfiguration}) for scene in scenes.mitems: scene.addShaderGlobal("projection", Unit4F32) scene.addShaderGlobal("view", Unit4F32) - engine.loadScene(scene) + engine.LoadScene(scene) var size = 1'f32 @@ -87,8 +87,8 @@ "view", Scale(size, size, size) * Rotate(elevation, NewVec3f(1, 0, 0)) * Rotate(azimut, Yf32) ) - engine.renderScene(scenes[currentScene]) - engine.destroy() + engine.RenderScene(scenes[currentScene]) + engine.Destroy() when isMainModule: main()
--- a/tests/test_panel.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/tests/test_panel.nim Tue Jun 04 22:08:48 2024 +0700 @@ -20,8 +20,8 @@ proc main() = # setup engine - var engine = initEngine("Test panels") - engine.initRenderer([]) + var engine = InitEngine("Test panels") + engine.InitRenderer([]) const B = [0'u8, 0'u8, 0'u8, 255'u8] const T = [0'u8, 0'u8, 0'u8, 0'u8] @@ -62,7 +62,7 @@ scene.add button scene.add help_text scene.add origin - engine.loadScene(scene) + engine.LoadScene(scene) while engine.UpdateInputs() and not KeyIsDown(Escape): if KeyWasPressed(F1): @@ -91,8 +91,8 @@ origin.refresh() help_text.refresh() - engine.renderScene(scene) - engine.destroy() + engine.RenderScene(scene) + engine.Destroy() when isMainModule:
--- a/tests/test_vulkan_wrapper.nim Tue Jun 04 20:51:22 2024 +0700 +++ b/tests/test_vulkan_wrapper.nim Tue Jun 04 22:08:48 2024 +0700 @@ -183,7 +183,7 @@ result = @[r1, r2] proc main() = - var engine = initEngine("Test") + var engine = InitEngine("Test") # INIT RENDERER: const @@ -214,7 +214,7 @@ vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", fragmentCode = "color = outcolor;", ) - engine.initRenderer({ + engine.InitRenderer({ Mat1Type: shaderConfiguration1, Mat1Type: shaderConfiguration1, Mat2Type: shaderConfiguration1, @@ -231,7 +231,7 @@ ] for scene in scenes.mitems: - engine.loadScene(scene) + engine.LoadScene(scene) # MAINLOOP echo "Setup successfull, start rendering" @@ -240,13 +240,13 @@ echo "rendering scene ", scene.name for i in 0 ..< 1000: if not engine.UpdateInputs() or KeyIsDown(Escape): - engine.destroy() + engine.Destroy() return - engine.renderScene(scene) + engine.RenderScene(scene) # cleanup echo "Start cleanup" - engine.destroy() + engine.Destroy() when isMainModule: main()