diff options
Diffstat (limited to 'chickadee/graphics/pipeline.scm')
-rw-r--r-- | chickadee/graphics/pipeline.scm | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/chickadee/graphics/pipeline.scm b/chickadee/graphics/pipeline.scm new file mode 100644 index 0000000..84db3cb --- /dev/null +++ b/chickadee/graphics/pipeline.scm @@ -0,0 +1,107 @@ +;;; 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: +;; +;; GPU pipelines. +;; +;;; Code: + +(define-module (chickadee graphics pipeline) + #:use-module ((chickadee graphics backend) #:prefix gpu:) + #:use-module (chickadee graphics color) + #:use-module (chickadee graphics depth-stencil) + #:use-module (chickadee graphics layout) + #:use-module (chickadee graphics primitive) + #:use-module (ice-9 match) + #:use-module (srfi srfi-9) + #:use-module (srfi srfi-9 gnu) + #:export (make-render-pipeline + destroy-render-pipeline + render-pipeline? + render-pipeline-name + render-pipeline-shader + render-pipeline-primitive + render-pipeline-color-target + render-pipeline-depth+stencil + render-pipeline-vertex-layout + render-pipeline-binding-layout) + #:re-export (make-vertex-attribute + vertex-attribute? + vertex-attribute-format + vertex-attribute-offset + + make-vertex-buffer-layout + vertex-buffer-layout? + vertex-buffer-layout-stride + vertex-buffer-layout-step-mode + vertex-buffer-layout-attributes + + make-texture-layout + texture-layout? + texture-layout-sample-type + texture-layout-dimension + texture-layout-multisample? + + make-sampler-layout + sampler-layout? + sampler-layout-type + + make-buffer-layout + buffer-layout? + buffer-layout-type + buffer-layout-min-size)) + +(define shader-handle (@@ (chickadee graphics shader) shader-handle)) + +(define-record-type <render-pipeline> + (%make-render-pipeline gpu handle name shader primitive color-target + depth+stencil vertex-layout binding-layout) + render-pipeline? + (gpu render-pipeline-gpu) + (handle render-pipeline-handle) + (name render-pipeline-name) + (destroyed? render-pipeline-destroyed? set-render-pipeline-destroyed!) + (shader render-pipeline-shader) + (primitive render-pipeline-primitive) + (color-target render-pipeline-color-target) + (depth+stencil render-pipeline-depth+stencil) + (vertex-layout render-pipeline-vertex-layout) + (binding-layout render-pipeline-binding-layout)) + +(define (print-render-pipeline pipeline port) + (format port "#<render-pipeline name: ~a>" + (render-pipeline-name pipeline))) + +(set-record-type-printer! <render-pipeline> print-render-pipeline) + +(define* (make-render-pipeline #:key name shader + (primitive (make-primitive-mode)) + (color-target (make-color-target)) + depth+stencil + (vertex-layout #()) + (binding-layout #())) + (let* ((gpu (gpu:current-gpu)) + (handle (gpu:make-render-pipeline gpu (shader-handle shader) + primitive color-target depth+stencil + vertex-layout binding-layout))) + (%make-render-pipeline gpu handle name shader primitive color-target + depth+stencil vertex-layout binding-layout))) + +(define (destroy-render-pipeline pipeline) + (unless (render-pipeline-destroyed? pipeline) + (gpu:destroy-render-pipeline (gpu:current-gpu) + (render-pipeline-handle pipeline)) + (set-render-pipeline-destroyed! pipeline #t))) |