forked from hupe1980/go-mtl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_pass.go
More file actions
54 lines (43 loc) · 1.79 KB
/
Copy pathrender_pass.go
File metadata and controls
54 lines (43 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//go:build darwin
// +build darwin
package mtl
/*
#include "render_pass.h"
*/
import "C"
import (
"errors"
"unsafe"
)
// RenderPipelineColorAttachmentDescriptor represents a color attachment descriptor for a render pipeline.
type RenderPipelineColorAttachmentDescriptor struct {
// PixelFormat is the pixel format of the color attachment's texture.
PixelFormat PixelFormat
}
// RenderPipelineDescriptor represents a descriptor for a render pipeline.
type RenderPipelineDescriptor struct {
// VertexFunction is a programmable function that processes individual vertices in a rendering pass.
VertexFunction Function
// FragmentFunction is a programmable function that processes individual fragments in a rendering pass.
FragmentFunction Function
// ColorAttachments is an array of attachments that store color data.
ColorAttachments [1]RenderPipelineColorAttachmentDescriptor
}
// RenderPipelineState represents the state of a render pipeline.
type RenderPipelineState struct {
renderPipelineState unsafe.Pointer
}
// NewRenderPipelineStateWithDescriptor creates a new render pipeline state with the provided descriptor.
// It returns the created RenderPipelineState or an error if the creation fails.
func (d Device) NewRenderPipelineStateWithDescriptor(rpd RenderPipelineDescriptor) (RenderPipelineState, error) {
descriptor := C.struct_RenderPipelineDescriptor{
VertexFunction: rpd.VertexFunction.function,
FragmentFunction: rpd.FragmentFunction.function,
ColorAttachment0PixelFormat: C.uint16_t(rpd.ColorAttachments[0].PixelFormat),
}
rps := C.Device_NewRenderPipelineStateWithDescriptor(d.device, descriptor)
if rps.RenderPipelineState == nil {
return RenderPipelineState{}, errors.New(C.GoString(rps.Error))
}
return RenderPipelineState{rps.RenderPipelineState}, nil
}