summaryrefslogtreecommitdiff
path: root/chickadee/graphics/depth-stencil.scm
blob: a3fac63cd284a5040baa683c71716af629770851 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;;; Chickadee Game Toolkit
;;; Copyright © 2023 David Thompson <dthompson2@worcester.edu>
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at
;;;
;;;    http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.

;;; Commentary
;;
;; Depth/stencil buffer configuration.
;;
;;; Code:

(define-module (chickadee graphics depth-stencil)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-9)
  #:export (<stencil-face>
            make-stencil-face
            stencil-face?
            stencil-face-compare
            stencil-face-fail-op
            stencil-face-depth-fail-op
            stencil-face-pass-op

            <depth-test>
            make-depth-test
            depth-test
            depth-test-compare
            depth-test-write?

            <depth+stencil>
            make-depth+stencil
            depth+stencil?
            depth+stencil-format
            depth+stencil-depth-write-enabled?
            depth+stencil-compare-function
            depth+stencil-stencil-front
            depth+stencil-stencil-back
            depth+stencil-stencil-read-mask
            depth+stencil-stencil-write-mask

            <depth-operation>
            make-depth-operation
            depth-operation?
            depth-operation-clear-value
            depth-operation-load-op
            depth-operation-store-op
            depth-operation-read-only?

            <stencil-operation>
            make-stencil-operation
            stencil-operation?
            stencil-operation-clear-value
            stencil-operation-load-op
            stencil-operation-store-op
            stencil-operation-read-only?))

(define-record-type <stencil-face>
  (%make-stencil-face compare fail-op depth-fail-op pass-op)
  stencil-face?
  (compare stencil-face-compare)
  (fail-op stencil-face-fail-op)
  (depth-fail-op stencil-face-depth-fail-op)
  (pass-op stencil-face-pass-op))

(define* (make-stencil-face #:key (compare 'always) (fail-op 'keep)
                            (depth-fail-op 'keep) (pass-op 'keep))
  (%make-stencil-face compare fail-op depth-fail-op pass-op))

(define-record-type <depth-test>
  (%make-depth-test compare write?)
  depth-test?
  (compare depth-test-compare)
  (write? depth-test-write?))

(define* (make-depth-test #:key (compare 'less) write?)
  (%make-depth-test compare write?))

(define-record-type <depth+stencil>
  (%make-depth+stencil format depth-test stencil-front
                       stencil-back stencil-read-mask stencil-write-mask)
  depth+stencil?
  (format depth+stencil-format)
  (depth-test depth+stencil-depth-test)
  (stencil-front depth+stencil-stencil-front)
  (stencil-back depth+stencil-stencil-back)
  (stencil-read-mask depth+stencil-stencil-read-mask)
  (stencil-write-mask depth+stencil-stencil-write-mask))

(define* (make-depth+stencil #:key
                             (format 'depth24plus-stencil8)
                             depth-test
                             stencil-face
                             (stencil-front stencil-face)
                             (stencil-back stencil-face)
                             (stencil-read-mask #xffffFFFF)
                             (stencil-write-mask #xffffFFFF))
  (%make-depth+stencil format depth-test stencil-front
                       stencil-back stencil-read-mask stencil-write-mask))

(define-record-type <depth-operation>
  (%make-depth-operation clear-value load-op store-op read-only?)
  depth-operation?
  (clear-value depth-operation-clear-value)
  (load-op depth-operation-load-op)
  (store-op depth-operation-store-op)
  (read-only? depth-operation-read-only?))

(define* (make-depth-operation #:key
                               (clear-value 0.0)
                               (load-op 'clear)
                               (store-op 'store)
                               read-only?)
  (%make-depth-operation clear-value load-op store-op read-only?))

(define-record-type <stencil-operation>
  (%make-stencil-operation clear-value load-op store-op read-only?)
  stencil-operation?
  (clear-value stencil-operation-clear-value)
  (load-op stencil-operation-load-op)
  (store-op stencil-operation-store-op)
  (read-only? stencil-operation-read-only?))

(define* (make-stencil-operation #:key
                                 (clear-value #x00000000)
                                 (load-op 'clear)
                                 (store-op 'store)
                                 read-only?)
  (%make-stencil-operation clear-value load-op store-op read-only?))