Skip to content

Commit 38929fe

Browse files
author
Mike Solomon
committed
Adds gpu texture
1 parent ee75cfe commit 38929fe

3 files changed

Lines changed: 148 additions & 0 deletions

File tree

src/Web/GPU/GPUTexture.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const createViewImpl = (texture) => (descriptor) => () => texture.createView(descriptor);
2+
export const destroyImpl = (texture) => () => texture.destroy();
3+
export const widthImpl = (texture) => () => texture.width;
4+
export const heightImpl = (texture) => () => texture.height;
5+
export const depthOrArrayLayersImpl = (texture) => () => texture.depthOrArrayLayers;
6+
export const mipLevelCountImpl = (texture) => () => texture.mipLevelCount;
7+
export const sampleCountImpl = (texture) => () => texture.sampleCount;
8+
export const dimensionImpl = (texture) => () => texture.dimension;
9+
export const formatImpl = (texture) => () => texture.format;
10+
export const usageImpl = (texture) => () => texture.usage;

src/Web/GPU/GPUTexture.purs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
module Web.GPU.GPUTexture
2+
( TextureViewDescriptor
3+
, createView
4+
, destroy
5+
, width
6+
, height
7+
, depthOrArrayLayers
8+
, mipLevelCount
9+
, sampleCount
10+
, dimension
11+
, format
12+
, usage
13+
) where
14+
15+
import Prelude
16+
17+
import Effect (Effect)
18+
import Web.GPU.GPUTextureAspect (GPUTextureAspect)
19+
import Web.GPU.GPUTextureDimension (GPUTextureDimension)
20+
import Web.GPU.GPUTextureFormat (GPUTextureFormat)
21+
import Web.GPU.GPUTextureUsage (GPUTextureUsage)
22+
import Web.GPU.GPUTextureViewDimension (GPUTextureViewDimension)
23+
import Web.GPU.Internal.ConvertibleOptions (class ConvertOption, class ConvertOptionsWithDefaults, convertOptionsWithDefaults)
24+
import Web.GPU.Internal.Types (GPUTexture, GPUTextureView)
25+
import Web.GPU.Internal.Undefinable (Undefinable, defined, undefined)
26+
import Web.GPU.Internal.Unsigned (GPUIntegerCoordinate, GPUSize32)
27+
28+
type GPUTextureViewDescriptorOptional =
29+
( aspect :: Undefinable GPUTextureAspect
30+
, baseMipLevel :: Undefinable GPUIntegerCoordinate
31+
, baseArrayLayer :: Undefinable GPUIntegerCoordinate
32+
)
33+
34+
type GPUTextureViewDescriptor =
35+
( format :: GPUTextureFormat
36+
, dimension :: GPUTextureViewDimension
37+
, mipLevelCount :: GPUIntegerCoordinate
38+
, arrayLayerCount :: GPUIntegerCoordinate
39+
| GPUTextureViewDescriptorOptional
40+
)
41+
42+
defaultGPUTextureViewDescriptorOptions :: { | GPUTextureViewDescriptorOptional }
43+
defaultGPUTextureViewDescriptorOptions =
44+
{ aspect: undefined
45+
, baseMipLevel: undefined
46+
, baseArrayLayer: undefined
47+
}
48+
49+
data TextureViewDescriptor = TextureViewDescriptor
50+
51+
instance ConvertOption TextureViewDescriptor "aspect" GPUTextureAspect (Undefinable GPUTextureAspect) where
52+
convertOption _ _ = defined
53+
54+
instance ConvertOption TextureViewDescriptor "baseMipLevel" GPUIntegerCoordinate (Undefinable GPUIntegerCoordinate) where
55+
convertOption _ _ = defined
56+
57+
instance ConvertOption TextureViewDescriptor "baseArrayLayer" GPUIntegerCoordinate (Undefinable GPUIntegerCoordinate) where
58+
convertOption _ _ = defined
59+
60+
foreign import createViewImpl :: GPUTexture -> { | GPUTextureViewDescriptor } -> Effect GPUTextureView
61+
62+
createView
63+
:: forall provided
64+
. ConvertOptionsWithDefaults TextureViewDescriptor { | GPUTextureViewDescriptorOptional } { | provided } { | GPUTextureViewDescriptor }
65+
=> GPUTexture
66+
-> { | provided }
67+
-> Effect GPUTextureView
68+
createView gpuDevice provided = createViewImpl gpuDevice all
69+
where
70+
all :: { | GPUTextureViewDescriptor }
71+
all = convertOptionsWithDefaults TextureViewDescriptor defaultGPUTextureViewDescriptorOptions provided
72+
73+
foreign import destroyImpl :: GPUTexture -> Effect Unit
74+
75+
destroy :: GPUTexture -> Effect Unit
76+
destroy = destroyImpl
77+
78+
foreign import widthImpl :: GPUTexture -> Effect GPUIntegerCoordinate
79+
80+
width :: GPUTexture -> Effect GPUIntegerCoordinate
81+
width = widthImpl
82+
83+
foreign import heightImpl :: GPUTexture -> Effect GPUIntegerCoordinate
84+
85+
height :: GPUTexture -> Effect GPUIntegerCoordinate
86+
height = heightImpl
87+
88+
foreign import depthOrArrayLayersImpl :: GPUTexture -> Effect GPUIntegerCoordinate
89+
90+
depthOrArrayLayers :: GPUTexture -> Effect GPUIntegerCoordinate
91+
depthOrArrayLayers = depthOrArrayLayersImpl
92+
93+
foreign import mipLevelCountImpl :: GPUTexture -> Effect GPUIntegerCoordinate
94+
95+
mipLevelCount :: GPUTexture -> Effect GPUIntegerCoordinate
96+
mipLevelCount = mipLevelCountImpl
97+
98+
foreign import sampleCountImpl :: GPUTexture -> Effect GPUSize32
99+
100+
sampleCount :: GPUTexture -> Effect GPUSize32
101+
sampleCount = sampleCountImpl
102+
103+
foreign import dimensionImpl :: GPUTexture -> Effect GPUTextureDimension
104+
105+
dimension :: GPUTexture -> Effect GPUTextureDimension
106+
dimension = dimensionImpl
107+
108+
foreign import formatImpl :: GPUTexture -> Effect GPUTextureFormat
109+
110+
format :: GPUTexture -> Effect GPUTextureFormat
111+
format = formatImpl
112+
113+
foreign import usageImpl :: GPUTexture -> Effect GPUTextureUsage
114+
115+
usage :: GPUTexture -> Effect GPUTextureUsage
116+
usage = usageImpl

src/Web/GPU/GPUTextureAspect.purs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Web.GPU.GPUTextureAspect
2+
( GPUTextureAspect
3+
, all
4+
, depthOnly
5+
, stencilOnly
6+
) where
7+
8+
import Prelude
9+
10+
newtype GPUTextureAspect = GPUTextureAspect String
11+
12+
derive instance Eq GPUTextureAspect
13+
derive instance Ord GPUTextureAspect
14+
derive newtype instance Show GPUTextureAspect
15+
16+
all :: GPUTextureAspect
17+
all = GPUTextureAspect "all"
18+
19+
stencilOnly :: GPUTextureAspect
20+
stencilOnly = GPUTextureAspect "stencil-only"
21+
depthOnly :: GPUTextureAspect
22+
depthOnly = GPUTextureAspect "depth-only"

0 commit comments

Comments
 (0)