Mercurial > games > semicongine
comparison semiconginev2/image.nim @ 1252:01e9f41d35b1
add:support for push constants
author | sam <sam@basx.dev> |
---|---|
date | Fri, 26 Jul 2024 23:04:01 +0700 |
parents | c15770761865 |
children |
comparison
equal
deleted
inserted
replaced
1251:3f98ad20a9d3 | 1252:01e9f41d35b1 |
---|---|
14 imageview*: VkImageView | 14 imageview*: VkImageView |
15 sampler*: VkSampler | 15 sampler*: VkSampler |
16 isRenderTarget*: bool = false | 16 isRenderTarget*: bool = false |
17 samples*: VkSampleCountFlagBits = VK_SAMPLE_COUNT_1_BIT | 17 samples*: VkSampleCountFlagBits = VK_SAMPLE_COUNT_1_BIT |
18 | 18 |
19 proc LoadImage*[T: PixelType](pngData: seq[uint8]): Image[T] = | 19 proc LoadImageData*[T: PixelType](pngData: string|seq[uint8]): Image[T] = |
20 when T is Gray: | 20 when T is Gray: |
21 let pngType = 0.cint | 21 let pngType = 0.cint |
22 elif T is BGRA: | 22 elif T is BGRA: |
23 let pngType = 6.cint | 23 let pngType = 6.cint |
24 | 24 |
36 when T is BGRA: # converkt to BGRA | 36 when T is BGRA: # converkt to BGRA |
37 for i in 0 ..< result.data.len: | 37 for i in 0 ..< result.data.len: |
38 swap(result.data[i][0], result.data[i][2]) | 38 swap(result.data[i][0], result.data[i][2]) |
39 | 39 |
40 proc LoadImage*[T: PixelType](path: string, package = DEFAULT_PACKAGE): Image[T] = | 40 proc LoadImage*[T: PixelType](path: string, package = DEFAULT_PACKAGE): Image[T] = |
41 assert path.splitFile().ext.toLowerAscii == ".png" | 41 assert path.splitFile().ext.toLowerAscii == ".png", "Unsupported image type: " & path.splitFile().ext.toLowerAscii |
42 when T is Gray: | 42 when T is Gray: |
43 let pngType = 0.cint | 43 let pngType = 0.cint |
44 elif T is BGRA: | 44 elif T is BGRA: |
45 let pngType = 6.cint | 45 let pngType = 6.cint |
46 | 46 |
47 result = LoadImage[T](loadResource_intern(path, package = package).readAll()) | 47 result = LoadImageData[T](loadResource_intern(path, package = package).readAll()) |
48 | 48 |
49 | 49 |
50 proc toPNG[T: PixelType](image: Image[T]): seq[uint8] = | 50 proc toPNG[T: PixelType](image: Image[T]): seq[uint8] = |
51 when T is Gray: | 51 when T is Gray: |
52 let pngType = 0 # hardcoded in lodepng.h | 52 let pngType = 0 # hardcoded in lodepng.h |