graphicsdriver/metal: Specify the texture type explicitly

This commit is contained in:
Hajime Hoshi 2020-06-26 23:36:23 +09:00
parent a1abe6b728
commit 9f76b96c1f
6 changed files with 17 additions and 0 deletions

View File

@ -435,6 +435,7 @@ func (g *Graphics) genNextImageID() driver.ImageID {
func (g *Graphics) NewImage(width, height int) (driver.Image, error) {
g.checkSize(width, height)
td := mtl.TextureDescriptor{
TextureType: mtl.TextureType2D,
PixelFormat: mtl.PixelFormatRGBA8UNorm,
Width: graphics.InternalImageSize(width),
Height: graphics.InternalImageSize(height),

View File

@ -150,6 +150,7 @@ fragment float4 FragmentShader(Vertex in [[stage_in]]) {
// Create an output texture to render into.
td := mtl.TextureDescriptor{
TextureType: mtl.TextureType2D,
PixelFormat: mtl.PixelFormatRGBA8UNorm,
Width: 80,
Height: 20,

View File

@ -87,6 +87,16 @@ const (
FeatureSet_macOS_ReadWriteTextureTier2 FeatureSet = 10002
)
// TextureType defines The dimension of each image, including whether multiple images are arranged into an array or
// a cube.
//
// Reference: https://developer.apple.com/documentation/metal/mtltexturetype
type TextureType uint16
const (
TextureType2D TextureType = 2
)
// PixelFormat defines data formats that describe the organization
// and characteristics of individual pixels in a texture.
//
@ -362,6 +372,7 @@ type ClearColor struct {
//
// Reference: https://developer.apple.com/documentation/metal/mtltexturedescriptor.
type TextureDescriptor struct {
TextureType TextureType
PixelFormat PixelFormat
Width int
Height int
@ -481,6 +492,7 @@ func (d Device) MakeBufferWithLength(length uintptr, opt ResourceOptions) Buffer
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433425-maketexture.
func (d Device) MakeTexture(td TextureDescriptor) Texture {
descriptor := C.struct_TextureDescriptor{
TextureType: C.uint16_t(td.TextureType),
PixelFormat: C.uint16_t(td.PixelFormat),
Width: C.uint_t(td.Width),
Height: C.uint_t(td.Height),

View File

@ -69,6 +69,7 @@ struct RenderPassDescriptor {
};
struct TextureDescriptor {
uint16_t TextureType;
uint16_t PixelFormat;
uint_t Width;
uint_t Height;

View File

@ -113,6 +113,7 @@ void *Device_MakeBufferWithLength(void *device, size_t length,
void *Device_MakeTexture(void *device, struct TextureDescriptor descriptor) {
MTLTextureDescriptor *textureDescriptor = [[MTLTextureDescriptor alloc] init];
textureDescriptor.textureType = descriptor.TextureType;
textureDescriptor.pixelFormat = descriptor.PixelFormat;
textureDescriptor.width = descriptor.Width;
textureDescriptor.height = descriptor.Height;

View File

@ -93,6 +93,7 @@ fragment float4 FragmentShader(Vertex in [[stage_in]]) {
// Create an output texture to render into.
td := mtl.TextureDescriptor{
TextureType: mtl.TextureType2D,
PixelFormat: mtl.PixelFormatRGBA8UNorm,
Width: 512,
Height: 512,